In: Advanced Math
1.Use Newton's method to find all solutions of the equation correct to six decimal places. (Enter your answers as a comma-separated list.)
ln(x) = 1/(x-3)
2. Use Newton's method to find all solutions of the equation correct to eight decimal places. Start by drawing a graph to find initial approximations. (Enter your answers as a comma-separated list.)
6e−x2 sin(x) = x2 − x + 1
(Question 1) MATLAB Script:
close all
clear
clc
syms x
f = log(x) * (x - 3) - 1; % f(x) = 0
df = diff(f); % f'(x)
tol = 1e-6; % Error tolerance (6 decimal places)
% Plot f(x) for locating approximate solutions
x_vals = 0:0.01:5;
plot(x_vals, subs(f, x_vals))
xlabel('x'), ylabel('f(x)')
title('f(x) = ln(x) * (x - 3) - 1')
grid on
fprintf('From the graph, the approximate roots are: 0.65 and 3.76\n\n')
x0 = 0.65; % Initial guess 1
result = newtraph(f,df,x0,tol);
fprintf('Solution (using initial guess = %.2f): %.6f\n', x0,
result)
x0 = 3.76; % Initial guess 2
result = newtraph(f,df,x0,tol);
fprintf('Solution (using initial guess = %.2f): %.6f\n', x0,
result)
% Newton's Method
function x = newtraph(f,df,x0,tol)
x = x0;
while true
x_ = x; % Backup previous iteration's result
x = double(x - subs(f, x)/subs(df, x)); % Newton Update Rule
if abs(x_ - x) < tol % Termination condition
break
end
end
end
Plot:
Output:
From the graph, the approximate roots are: 0.65 and 3.76
Solution (using initial guess = 0.65): 0.653060
Solution (using initial guess = 3.76): 3.755701