The rootfinding problem, Exercise 1
- x2=e−x, over [-2, 2]
- Rewrite: f(x)=e−x−x2
using FundamentalsNumericalComputation
f1(x) = exp(-x) - x^(2.);
x1 = -2:0.1:2;
plot(x1, f1.(x1))
#plot(f1, -2, 2)
There should be one root.
s1 = nlsolve(x->f1(x[1]), [0.75], ftol = 1e-14);
[s1.zero f1.(s1.zero)]
- inverse of the derivative evaluated at the root
f1d(x) = -exp(-x) - 2x;
abs.(f1d.(s1.zero))
1 ./ abs.(f1d.(s1.zero))