Error in using solve function.
古いコメントを表示
m1=[1,1]';m2=[3,3]';
m=[m1 m2];
S(:,:,1)=[0.1 -0.08;-0.08 0.2];
S(:,:,2)=[0.1 0;0 0.1];
P=[0.7 0.3];
N=500;
x1=linspace(0,4,N);
syms x2
x=[x1(1) x2]';
xx1=solve(-1/2*x'*inv(S(:,:,1))*x+m1'*inv(S(:,:,1))*x - 1/2*m1'*inv(S(:,:,1))*m1 -1/2*log(det(S(:,:,1))))
xx2=solve(-1/2*x'*inv(S(:,:,1))*x+m1'*inv(S(:,:,1))*x - 1/2*m1'*inv(S(:,:,1))*m1 -1/2*log(det(S(:,:,1))) - (-1/2*x'*inv(S(:,:,2))*x+m2'*inv(S(:,:,2))*x - 1/2*m2'*inv(S(:,:,2))*m2 -1/2*log(det(S(:,:,2))))== 0,0,2);
My code is on upper.
I dont know why xx1 is empty sym and why the code is not working.
i dont have someone to ask.
so i need your help.
3 件のコメント
Walter Roberson
2014 年 1 月 20 日
What is the final ,0,2 intended to indicate for solve() for xx2 ? You can give solve() a name/value pair at that point, but not two numeric values in a row.
Walter Roberson
2014 年 1 月 20 日
You use ' in several places. Is that intended to represent plain transpose, or is intended to represent conjugate transpose? Conjugate transpose is the ' operation, but plain transpose is the .' operator
Do-Ui
2014 年 1 月 20 日
回答 (1 件)
Walter Roberson
2014 年 1 月 20 日
In its present form, if you convert your decimal values into rationals, then the expression you are trying to solve() to get xx1 is
-(125/34) * x2 * conj(x2) + (225/17) * conj(x2) - 575/34 - (1/2) * log(17/1250)
This does not have any solutions, not even for complex x2. To show this, you can make the substitution that x2 = X + sqrt(-1)*Y with X and Y real. Simplify, and then solve() the result for Y. If you examine the result, you will find that it is not possible for the resulting expression to be real-valued. By way of contradiction this establishes that x2 cannot be broken up into real and imaginary parts and so x2 cannot be any possible complex value, including the case where x2 is real-valued.
If your expression was intended to use plain transpose instead of conjugate transpose then there might possibly be solutions.
2 件のコメント
Do-Ui
2014 年 1 月 20 日
Walter Roberson
2014 年 1 月 20 日
Change all of the ' to .'
Once you have done that, solve() should work fine. There will be two answers for xx1 and two answers for xx2 -- complex conjugate pairs in each case. The solutions will be complex.
カテゴリ
ヘルプ センター および File Exchange で Conversion Between Symbolic and Numeric についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!