how to solve non-linear equations

2 次查看(过去 30 天)
Chithralekha
Chithralekha 2012-11-30
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

回答(2 个)

Walter Roberson
Walter Roberson 2012-11-30
编辑:Walter Roberson 2012-11-30
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;

Muruganandham Subramanian
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..

标签

Community Treasure Hunt

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

Start Hunting!

Translated by