Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Solving a nonlinear system with fsolve

Subject: Solving a nonlinear system with fsolve

From: Tot

Date: 30 Apr, 2013 12:53:09

Message: 1 of 3

Hi,

I have a problem finding the right solution of a nonlinear system with fsolve.
I tried with 2 equations instead of n equations and I see that fsolve doesn't find the exact solution of the system.
Here is the equations :
------------------------------------------------------------
function F=test(T) % T is the unknown column (T(1),T(2))'

%Input values
n=2;
t0=8;
tstar=zeros(n,1);
C=zeros(n,1);
P=600;
mu=zeros(n,1);

C(1,1)=18;
C(2,1)=18;
mu(1,1)=1;
mu(2,1)=2;
tstar(1,1)=6;
tstar(2,1)=3;
S=sum(C)+P;

F(1,1)=C(1,1)-S*((exp((T(1)-tstar(1,1))/mu(1,1)))-(mu(2,1)/(mu(1,1)+mu(2,1)))*(exp((T(1)-tstar(1,1))/mu(1,1)))*(exp((T(2)-tstar(2,1))/mu(2,1))));

F(2,1)=C(2,1)-S*((exp((T(2)-tstar(2,1))/mu(2,1)))-(mu(1,1)/(mu(1,1)+mu(2,1)))*(exp((T(1)-tstar(1,1))/mu(1,1)))*(exp((T(2)-tstar(2,1))/mu(2,1))));

end
----------------------------------------------------------
Then I execute:

fsolve(@(T) test(T),[1;1])

and I find one correct value but the second is not right. This system can be solved easily : replace exp( (T1-tstar1)/mu1 ) by x1, the same thing for x2, then you solve the second degree polynomial equation exactly and you deduce T1 and T2.
The T2 value found by fsolve is always right but T1 is always wrong, except when all the parameters (mu, C, tstar) are the same both for 1 and 2. In this case, T1=T2.

Why doesn't fsolve give me the right solutions for a simple system of 2 equations? What algorithm should I use for this kind of system, knowing that I want to solve it for n equations?

Please don't hesitate if it is not clear.
Najib

Subject: Solving a nonlinear system with fsolve

From: Tot

Date: 30 Apr, 2013 13:00:10

Message: 2 of 3

Ok forget it I just found my mistake.

Subject: Solving a nonlinear system with fsolve

From: Alan_Weiss

Date: 30 Apr, 2013 13:16:33

Message: 3 of 3

On 4/30/2013 8:53 AM, Tot wrote:
> Hi,
>
> I have a problem finding the right solution of a nonlinear system with
> fsolve.
> I tried with 2 equations instead of n equations and I see that fsolve
> doesn't find the exact solution of the system.
> Here is the equations :
> ------------------------------------------------------------
> function F=test(T) % T is the unknown column (T(1),T(2))'
>
> %Input values
> n=2;
> t0=8;
> tstar=zeros(n,1);
> C=zeros(n,1);
> P=600;
> mu=zeros(n,1);
>
> C(1,1)=18;
> C(2,1)=18;
> mu(1,1)=1;
> mu(2,1)=2;
> tstar(1,1)=6;
> tstar(2,1)=3;
> S=sum(C)+P;
>
> F(1,1)=C(1,1)-S*((exp((T(1)-tstar(1,1))/mu(1,1)))-(mu(2,1)/(mu(1,1)+mu(2,1)))*(exp((T(1)-tstar(1,1))/mu(1,1)))*(exp((T(2)-tstar(2,1))/mu(2,1))));
>
>
> F(2,1)=C(2,1)-S*((exp((T(2)-tstar(2,1))/mu(2,1)))-(mu(1,1)/(mu(1,1)+mu(2,1)))*(exp((T(1)-tstar(1,1))/mu(1,1)))*(exp((T(2)-tstar(2,1))/mu(2,1))));
>
>
> end
> ----------------------------------------------------------
> Then I execute:
>
> fsolve(@(T) test(T),[1;1])
>
> and I find one correct value but the second is not right. This system
> can be solved easily : replace exp( (T1-tstar1)/mu1 ) by x1, the same
> thing for x2, then you solve the second degree polynomial equation
> exactly and you deduce T1 and T2.
> The T2 value found by fsolve is always right but T1 is always wrong,
> except when all the parameters (mu, C, tstar) are the same both for 1
> and 2. In this case, T1=T2.
>
> Why doesn't fsolve give me the right solutions for a simple system of
> 2 equations? What algorithm should I use for this kind of system,
> knowing that I want to solve it for n equations?
>
> Please don't hesitate if it is not clear.
> Najib

You can find suggestions on improving results here:
http://www.mathworks.com/help/optim/ug/when-the-solver-fails.html#br7o7ou
http://www.mathworks.com/help/optim/ug/when-the-solver-might-have-succeeded.html#br44i8w
http://www.mathworks.com/help/optim/ug/when-the-solver-succeeds.html

Alan Weiss
MATLAB mathematical toolbox documentation

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us