# MATLAB: 4 non linear simultaneous equations

## MATLAB: 4 non linear simultaneous equations

equationfsolvesimultaneoussolver

I have the following 4 questions and want to solve them using fsolve
``F(1)=x(1)+x(3)-12.54;F(2)=x(2)+x(4)-12.245;F(3)= 2*x(1)+n(2)+n(3)-(1493/60);F(4) =(x(3)*x(2))/(x(1)*x(4))-1000;``

• Hi Misha
this is John BG >
1.
define the function to solve with in for instance a separate file
``function F=fun1(x,n)F(1)=x(1)+x(3)-12.54; F(2)=x(2)+x(4)-12.245; F(3)= 2*x(1)+n(2)+n(3)-(1493/60); F(4) =(x(3)*x(2))/(x(1)*x(4))-1000;``
2.
if choosing a single lucky start point, then for instance
``f1=@fun1x0=[1 1 1 1];n=[1 2 1 2];options = optimoptions('fsolve','Display','none','PlotFcn',@optimplotfirstorderopt);f2=@(x) f1(x,n)Y=fsolve(f2,x0) Y =     2.9951    4.5133    1.6388    0.0025``
3.
Not all start points allow fsolve to start, for instance starting x0 all nulls fsolve returns error
``x0=[0 0 0 0];Y=fsolve(f2,x0) Error using trustnleqn (line 28) Objective function is returning undefined values at initial point. FSOLVE cannot continue.   Error in fsolve (line 388)           trustnleqn(funfcn,x,verbosity,gradflag,options,defaultopt,f,JAC,...``
4.
A way to understand that there are multiple real roots is changing fsolve options to
.
``problem.options = optimoptions('fsolve','Display','none','PlotFcn',@optimplotfirstorderopt);problem.objective = f2;problem.x0 = [1 1 1 1];problem.solver = 'fsolve';Y=fsolve(problem)grid on``
. .