How do I iterate f(x)
1 次查看(过去 30 天)
显示 更早的评论
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
x_true = fzero(f,[0.01 0.1],optimset("Display","iter"));
2 个评论
Torsten
2023-1-26
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
2023-1-26
f = @(x)exp(x) - 2 - x - x.^2./2
fplot(f, [0.01 0.1])
There is no zero of the function within that range.
回答(1 个)
Alan Weiss
2023-1-27
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])
Number of iterations is not too high.
Alan Weiss
MATLAB mathematical toolbox documentation
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!