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:
About solving a non linear equation, fzero

Subject: About solving a non linear equation, fzero

From: Alejandro Mosiño

Date: 26 Nov, 2010 15:58:04

Message: 1 of 3

Hello everyone,

I have this problem. Assume that you use fzero to find a root for the following equation:

2*x + (x*(x + 5)^(1/2))/5 + 10=0

fzero fails! However, by doing some math, you can write the equation as:

x^2-100x-500=0.

If you apply fzero on this new equation, Matlab will return the correct aswer (104.77).

Usually i can't factorize the equation, then i need to find a way to solve the equation as in the former case. Do you have any suggestions?

Thank you very much,

Alejandro

Subject: About solving a non linear equation, fzero

From: Alejandro Mosiño

Date: 26 Nov, 2010 17:40:06

Message: 2 of 3

I found the mistake. It is simple:

104.77 is a fake solution.

Even when 107.44 solves: x^2-100x-500=0, it does not solve:

2*x + (x*(x + 5)^(1/2))/5 + 10=0.

The problem is that, when factorizing, we square both sides of the equation, and a minus sign "disappears" forever. Hence, we cant get back the long equation from the short one.

Thank you all,

A.

"Alejandro Mosiño" <Alejandro.Mosino@etu.univ-savoie.fr> wrote in message <icolec$9cl$1@fred.mathworks.com>...
> Hello everyone,
>
> I have this problem. Assume that you use fzero to find a root for the following equation:
>
> 2*x + (x*(x + 5)^(1/2))/5 + 10=0
>
> fzero fails! However, by doing some math, you can write the equation as:
>
> x^2-100x-500=0.
>
> If you apply fzero on this new equation, Matlab will return the correct aswer (104.77).
>
> Usually i can't factorize the equation, then i need to find a way to solve the equation as in the former case. Do you have any suggestions?
>
> Thank you very much,
>
> Alejandro

Subject: About solving a non linear equation, fzero

From: Miroslav Balda

Date: 26 Nov, 2010 20:46:04

Message: 3 of 3

"Alejandro Mosiño" <Alejandro.Mosino@etu.univ-savoie.fr> wrote in message <icolec$9cl$1@fred.mathworks.com>...
> Hello everyone,
>
> I have this problem. Assume that you use fzero to find a root for the following equation:
>
> 2*x + (x*(x + 5)^(1/2))/5 + 10=0

SNIP

Hi Alejandro,

I tried my function LMFnlsq from FEX
     www.mathworks.com/matlabcentral/fileexchange/17534.
with a very fast response:

 res = @(x) 2*x + (x*(x + 5)^(1/2))/5 + 10;
 [x,ssq,cnt] = LMFnlsq(res,1,'Display',-1)
******************************************************************* itr nfJ SUM(r^2) x dx
******************************************************************* 0 1 1.5600e+002 1.0000e+000 0.0000e+000
   1 2 1.7352e+000 -3.9353e+000 4.9353e+000
   2 3 1.9706e-002 -4.6571e+000 7.2180e-001
   3 4 9.8174e-005 -4.7633e+000 1.0620e-001
   4 5 9.8083e-009 -4.7722e+000 8.8607e-003
 
   5 6 1.1401e-016 -4.7723e+000 9.0388e-005
x =
   -4.7723
ssq =
  1.1401e-016
cnt =
     5
The solution is x=-4.7723, and has been obtained in 5 iterations. The sum of squares of the residual is about 1e-16, what is within a machine precission.
I hope it helps

Mira

Tags for 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