# How do I iterate f(x)

2 visualizaciones (últimos 30 días)
LILIA VERGARA el 26 de En. de 2023
Respondida: Alan Weiss el 27 de En. de 2023
using x^(0) = 0 and x^(1) = 5 as inital condition
I am trying to iterate f(x) up to 60 iterations or till the estimated relative error is less than 10^-6
note that f(x) = e^x - 2 - x - (x^2 / 2)
The code I have startead with has been giving me errors:
f = @(x)exp(x) - 2 - x - x.^2./2
f = function_handle with value:
@(x)exp(x)-2-x-x.^2./2
x_true = fzero(f,[0.01 0.1],optimset("Display","iter"));
Error using fzero
Function values at the interval endpoints must differ in sign.
##### 2 comentariosMostrar NingunoOcultar Ninguno
Torsten el 26 de En. de 2023
What do you mean by
I am trying to iterate f(x) up to 60 iterations or till the estimated relative error is less than 10^-6
?
Walter Roberson el 26 de En. de 2023
f = @(x)exp(x) - 2 - x - x.^2./2
f = function_handle with value:
@(x)exp(x)-2-x-x.^2./2
fplot(f, [0.01 0.1])
There is no zero of the function within that range.

Iniciar sesión para comentar.

### Respuestas (1)

Alan Weiss el 27 de En. de 2023
Is this what you are looking for?
f = @(x)exp(x) - 2 - x - x.^2./2;
t = linspace(0,5);
plot(t,f(t))
OK, there is a root in that interval. Find it.
[x,fval,eflag,output] = fzero(f,[0 5])
x = 1.5681
fval = 2.2204e-16
eflag = 1
output = struct with fields:
intervaliterations: 0 iterations: 11 funcCount: 13 algorithm: 'bisection, interpolation' message: 'Zero found in the interval [0, 5]'
Number of iterations is not too high.
Alan Weiss
MATLAB mathematical toolbox documentation
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

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