How can I solve the non linear algebraic equation system with a parameter
2 views (last 30 days)
Show older comments
Thimé Cianyi
on 13 Aug 2019
Commented: Star Strider
on 20 Aug 2019
I tried as shown below :
function F=root2d(x)
syms s
F(1)=46.263e+5*x(1)+0.288875*x(3)^2*x(2)*sin(x(4))-0.187375*x(2)^2*x(3)*sin(x(6))-1.5e+3*sin(x(5)); F(2)=237.807241*s*x(1)-0.7765*x(1)^3-2.07225*x(1)*x(2)^2-0.288875*x(1)^2*x(2)*cos(x(4))+0.187375*x(2)^2*x(3)*cos(x(6))-4.341625*x(1)*x(3)^2+1.5e3*cos(x(5)); F(3)=249.85e5*x(2)-0.09625*x(1)^3*sin(x(4))+0.374875*x(1)*x(2)*x(3)*sin(x(6)); F(4)=2311.76211*x(2)*(z-801)-10.7815*x(2)^3-2.07225*x(1)^2*x(2)-0.09625*x(1)^3*cos(x(4))+0.374875*x(1)*x(2)*x(3)*cos(x(6))-16.2345*x(3)^2*x(2); F(5)=938.16e5*x(3)+0.187375*x(1)*x(2)^2*sin(x(6)); F(6)=(11252.3953*s+3866749.2347199973)*x(3)+0.187375*x(1)*x(2)^2*cos(x(6))-4.341625*x(1)^2*x(3)-16.2345*x(2)^2*x(3)-51.815125*x(3)^3;
options = optimoptions('fsolve','Display','none','PlotFcn',@optimplotfirstorderopt); fun = @root2d; x0=[1,1,1,1,1,1]; x=fsolve(fun,x0,options)
This is the Error I am geting :
The following error occurred converting from sym to double: DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use VPA.
Error in root2d (line 6) F(2)=237.807241*s*x(1)-0.7765*x(1)^3-2.07225*x(1)*x(2)^2-0.288875*x(1)^2*x(2)*cos(x(4))+0.187375*x(2)^2*x(3)*cos(x(6))-4.341625*x(1)*x(3)^2+1.5e3*cos(x(5));
Error in fsolve (line 218) fuser = feval(funfcn{3},x,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
0 Comments
Accepted Answer
Star Strider
on 13 Aug 2019
You can use the matlabFunction function to create an anonymous function from ‘F’ so you can use it with fsolve. However, you still need to provide values for ‘s’ and ‘z’ in order to solve it for ‘x’ (that appears in the ‘root2d’ anonymous function as ‘in1’).
The Code —
syms s x z
x = sym('x', [1,6]);
F(1)=46.263e+5*x(1)+0.288875*x(3)^2*x(2)*sin(x(4))-0.187375*x(2)^2*x(3)*sin(x(6))-1.5e+3*sin(x(5));
F(2)=237.807241*s*x(1)-0.7765*x(1)^3-2.07225*x(1)*x(2)^2-0.288875*x(1)^2*x(2)*cos(x(4))+0.187375*x(2)^2*x(3)*cos(x(6))-4.341625*x(1)*x(3)^2+1.5e3*cos(x(5));
F(3)=249.85e5*x(2)-0.09625*x(1)^3*sin(x(4))+0.374875*x(1)*x(2)*x(3)*sin(x(6));
F(4)=2311.76211*x(2)*(z-801)-10.7815*x(2)^3-2.07225*x(1)^2*x(2)-0.09625*x(1)^3*cos(x(4))+0.374875*x(1)*x(2)*x(3)*cos(x(6))-16.2345*x(3)^2*x(2);
F(5)=938.16e5*x(3)+0.187375*x(1)*x(2)^2*sin(x(6));
F(6)=(11252.3953*s+3866749.2347199973)*x(3)+0.187375*x(1)*x(2)^2*cos(x(6))-4.341625*x(1)^2*x(3)-16.2345*x(2)^2*x(3)-51.815125*x(3)^3;
root2d = matlabFunction(F, 'Vars',{[x],s,z})
s = rand; % Provide Correct Value (Scalar)
z = rand; % Provide Correct Value (Scalar)
options = optimoptions('fsolve','Display','none','PlotFcn',@optimplotfirstorderopt);
fun = @(in1)root2d(in1,s,z);
x0=[1,1,1,1,1,1];
x=fsolve(fun,x0,options)
14 Comments
Star Strider
on 20 Aug 2019
As always, my pleasure!
I am quite happy that we were able to solve this!
More Answers (1)
John D'Errico
on 13 Aug 2019
Edited: John D'Errico
on 13 Aug 2019
You CANNOT use fsolve with a symbolic parameter in the problem. CANNOT. Fsolve is a numerical tool. It finds a root (if it can that is purely numerical.)
If you are willing to choose some specific value of s, then the result will be 6 equations in 6 unknowns. There will usually be multiple solutions to such a problem, especially when you have trig functions in there. Fsolve might find ONE of them, IF it converges to a valid solution. The result you get will be dependent on the starting values you provide.
You have a system of 6 equations in 6 unknowns, with one parameter that you want to leave in there, so the solutinos will be a function of s. Unfortunately, your system is complicated enough that it will surely not have any analytical solutino at all. Powers of the x(i), as well as having those variables inside and outside of trig functions mean that there will never be an analytical solution. So even if you wanted to try to use solve, where the result could be a function of a parameter, it will fail.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!