Determine if valid initial guess for closed numerical method

1 visualización (últimos 30 días)
Rachel Dawn
Rachel Dawn el 21 de Feb. de 2018
Comentada: Torsten el 22 de Feb. de 2018
If I'm given a function f(x), how can I determine whether say [0 1] or [1,2 ] are valid initial guesses for a closed numerical method, of solving f(x)=0.

Respuestas (1)

Torsten
Torsten el 21 de Feb. de 2018
Editada: Torsten el 21 de Feb. de 2018
If you want to use "fzero", you can first evaluate f in the endpoints of the interval [a b] you provide. If sign(f(a)*f(b)) < 0, you provide a valid initial guess.
Or did you want to ask something else - because your question was quite unclear ?
Best wishes
Torsten.
  4 comentarios
Rachel Dawn
Rachel Dawn el 21 de Feb. de 2018
Also, sorry for all the questions, but in the following code:
while(iteration <=100 && abs(xleft-xright)>10^-3
it's part of the bisection method, but what does that abs part imply? why is it necessary?
Torsten
Torsten el 22 de Feb. de 2018
Try
xa = 10;
xb = 21;
fxa = f(xa);
fxb = f(xb);
if fxa*fxb > 0
disp('Invalid initial guess.')
end
iteration = 1;
E = 0.1;
error_f = 1.0;
while (iteration < 100 && error_f >= E)
xc = (xa+xb)/2;
fxc = f(xc);
if fxc*fxa<0
xb = xc;
else
xa = xc;
fxa = fxc;
end
error_f = abs(fxc);
iteration = iteration+1;
end
xc
You do not need to include the abs-part from above in the while-statement because the number of iterations already determines the minimum length of the interval in which you search for the root.
Best wishes
Torsten.

Iniciar sesión para comentar.

Categorías

Más información sobre Functions 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