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 Comments

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.
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
' is just plain transpose and you can ignore the last 0,2. i thought it limit the x range. And right xx2 is my goal. i will use 'for' i=1:N and xx2(i) will give me what i want to know.

Sign in to comment.

Answers (1)

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 Comments

then what should i do to get the right answer? thank you for your help.
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.

Sign in to comment.

Asked:

on 20 Jan 2014

Commented:

on 20 Jan 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!