The function e^x −100x^2 =0 has three true solutions.Use Newton’s method to locate the solutions with tolerance 10^(−10).
MATLAB Script (Run it as a script, NOT from command window):
close all
clear
clc
f = @(x) exp(x) - 100*x.^2; % f(x)
fd = @(x) exp(x) - 200*x; % f'(x)
tol = 1e-10;
% Let's first plot the function to get approximate locations of
the roots
x = -10:0.001:10;
plot(x, f(x)), grid on
axis([-2 10 -2 2]), xlabel('x'), ylabel('f(x)'), title('f(x) =
exp(x) - 100x^2')
% Lets consider the initial guesses at x0 = -1, 1, 10.
fprintf('Roots: \n')
x0 = -1;
x = newton(f, fd, x0, tol);
fprintf('\t%.8f\n', x)
x0 = 1;
x = newton(f, fd, x0, tol);
fprintf('\t%.8f\n', x)
x0 = 10;
x = newton(f, fd, x0, tol);
fprintf('\t%.8f\n', x)
function xc = newton(f, fd, x0, tol)
xc = x0;
while true
xc = xc - f(xc)/fd(xc);
if abs(f(xc)) < tol
break;
end
end
end
Output:
Roots:
-0.09534462
0.10541197
8.99951058
Plot:
Get Answers For Free
Most questions answered within 1 hours.