how to solve non-linear equations
2 views (last 30 days)
Show older comments
syms w(0),w(1),w(2)
exp1=(w(0)^2+w(1)^2+w(2)^2)-A0;
exp2=(2*w(1)*(w(0)+w(2)))-A1;
exp3=(2*w(0)*w(2))-A2
sol=solve(exp1,exp2,exp3);
sol.w(0);
sol.w(1);
sol.w(2);
error message saying
"Error using ==> syms
Not a valid variable name".
please help me
0 Comments
Answers (2)
Walter Roberson
on 30 Nov 2012
Edited: Walter Roberson
on 30 Nov 2012
You cannot syms() a subscripted variable.
If you have a new enough MATLAB (R2012a or later), you can syms() a function giving a dummy variable name but not a number. For example
syms w(t)
If you have a new enough MATLAB (R2011b, maybe R2011a), you can sym() a vector or array of symbols into existence. Note this is sym and not syms:
w = sym('w', [1 3]);
This would create w(1), w(2), w(3) . Note it would not create w(0), which would be an invalid array subscript. 0 can be used as a function argument to a symbolic function, but functions do not declare individual symbols for the function values.
I suggest you change your variable names to not be subscripted:
syms w0 w1 w2
exp1=(w0^2+w1^2+w2^2)-A0;
exp2=(2*w1*(w0+w2))-A1;
exp3=(2*w0*w2)-A2
sol=solve(exp1,exp2,exp3);
sol.w0;
sol.w1;
sol.w2;
0 Comments
Muruganandham Subramanian
on 30 Nov 2012
you can't give variable name like w(0),w(1),w(2)..here variable is w and 0,1,2..are maybe iterations.. so declare variable clearly..
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!