find roots through iterative method

3 visualizaciones (últimos 30 días)
paula ro
paula ro el 5 de Abr. de 2015
Editada: Matt J el 9 de Abr. de 2015
I need to find 3 roots of an equation (e^x=3*x^2 - transcendent equation) through the iteration method in Matlab. What algorithm should I use?

Respuesta aceptada

Matt J
Matt J el 5 de Abr. de 2015
Editada: Matt J el 5 de Abr. de 2015
You can use FZERO, e.g.,
>> f=@(x) exp(x)-3*x.^2
>> [xroot,res]=fzero(f,.1)
You will need to provide an initial guess of each of the three roots, which you can obtain by plotting the function f(x)=e^x-3*x^2
  10 comentarios
paula ro
paula ro el 7 de Abr. de 2015
Actually my function is 3*x^2-exp(x). I don't understand how do you see all 3 roots. My graph shows one: 3.6-3.8. How exactly do I choose the next interval?
James Tursa
James Tursa el 8 de Abr. de 2015
Editada: James Tursa el 8 de Abr. de 2015
f = @(x) 3*x.^2-exp(x)
x = -5:.01:5;
plot(x,f(x))
grid on
All three roots are on the plot.

Iniciar sesión para comentar.

Más respuestas (1)

paula ro
paula ro el 8 de Abr. de 2015
Ok. But I need an iteration algorithm that finds these 3 roots without me manually extracting the intervals from the plot. The equation has multiple roots. I called the function 3 times with 'Bisection' and it just plots one root 0.9 and displays 'We stopped at interval (a,b)' Is there an algorithm that finds these 3 roots in a function? I only found for polynomials.
  2 comentarios
James Tursa
James Tursa el 8 de Abr. de 2015
Sounds like you are asking quite a lot from this algorithm. Determining good starting guesses for an arbitrary function is not at all trivial. Even determining just how many roots there are is not trivial. You are certainly not going to get some simple code on this forum that does this for you for an arbitrary function. Seems like there is going to have to be some manual work from you up front for doing this for any particular function you are interested in.
Matt J
Matt J el 9 de Abr. de 2015
Editada: Matt J el 9 de Abr. de 2015
But I need an iteration algorithm that finds these 3 roots without me manually extracting the intervals from the plot.
You've wasted a lot of time by concealing that requirement. I advised you to find the 3 roots in this manual way in my very first response and in several subsequent comments. You didn't even blink.
As James says, though, there is no method for finding all roots of an arbitrary function. One reason that this is impossible is because some functions have infinite roots, arbitrarily close together, even on a finite interval. Examples are f(x)=0 or f(x)=sin(1/x)

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by