How can I solve the non linear algebraic equation system with a parameter

3 views (last 30 days)
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.

Accepted Answer

Star Strider
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
Thimé Cianyi
Thimé Cianyi on 20 Aug 2019
Thank you dear Star, I’ve got it and I implemented the idea on my complicated code one, and this is in if the output:!

Sign in to comment.

More Answers (1)

John D'Errico
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.

Community Treasure Hunt

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

Start Hunting!