MATLAB Use the Newton-Raphson method to find the solutions to the non-linear equ
ID: 3801307 • Letter: M
Question
MATLAB
Use the Newton-Raphson method to find the solutions to the non-linear equations defined in sections (a)-(c), below. For each problem, the initial guess is given. As you write your program, for each problem, use subplot and plot commands first to plot the left hand side of the equation over the range of r specified for each case and then use hold on and plot commands to show the root of the equation on the same graph. In the other panel of the figure, use semilogy command to plot log of the absolute value of the error versus the iteration number. A typical output is shown in Figure 1. (a) 297 511 a 561 o 500 5000 25000 50 z E -0.4, 0.4] To 0.5 (b) Repeat part (a) for the following initial guesses: To 0.2 0.0 To -0.1 To -0.28 (c) atan(r) sin(z)Explanation / Answer
part (a) and part(b)
you can just change the initial guess in the following code to get answers for part(b)
x = 0.5; % initial guess value
x_old = 100;
error_tolerance = 0.0001;
absolute_error = abs(x_old-x);
abs_error_list = [absolute_error];
solutions_list = [x];
i = 0;
iteration = [i];
while (absolute_error > error_tolerance) && (x ~= 0)
x_old = x;
x = x - (100*(x^5) - 11*(x^2) - (511/50)*(x^3) + (561/5000)*x - (297/25000)) / (500*x^4 - 22*x -(511*3/500)*x^2 + (549/5000));
absolute_error = abs(x_old-x);
abs_error_list = [abs_error_list absolute_error];
solutions_list = [solutions_list x];
iteration = [iteration i];
i = i+1;
end
% printf("solution is %f ", x);
% printf("absolute error is %f ", absolute_error);
x = linspace(-0.4, 0.4);
f = (100*(x.^5) - 11*(x.^2) - (511/50)*(x.^3) + (561/5000)*x - (297/25000));
subplot(2,1,1);
plot(x,f, '--r');
hold on;
xsol = solutions_list;
f = (100*(xsol.^5) - 11*(xsol.^2) - (511/50)*(xsol.^3) + (561/5000)*xsol - (297/25000));
plot(solutions_list, f, '-ok');
subplot(2,1,2);
plot(iteration(2:end), abs_error_list(2:end), '-*b');
hold off;
-------------------------------------------------------------------------------------------------------------------
% part (c)
x = 0.6;
x_old = 100;
error_tolerance = 0.0001;
absolute_error = abs(x_old-x);
abs_error_list = [absolute_error];
solutions_list = [x];
i = 0;
iteration = [i];
while (absolute_error > error_tolerance) && (x ~= 0)
x_old = x;
x = x - (x*tan(x)-x^sin(x)-0.5) / (tan(x) - x^sin(x) * (sin(x)/x + cos(x)*log(x))+ x*(sec(x)*sec(x)));
absolute_error = abs(x_old-x);
abs_error_list = [abs_error_list absolute_error];
solutions_list = [solutions_list x];
iteration = [iteration i];
i = i+1;
end
% printf("solution is %f ", x);
% printf("absolute error is %f ", absolute_error);
x = linspace(0,1.4);
f = (x.*tan(x) - x.^sin(x) - 0.5);
subplot(2,1,1);
plot(x,f, '--r');
hold on;
xsol = solutions_list;
f = (xsol.*tan(xsol)-xsol.^sin(xsol)-0.5);
plot(solutions_list, f,'ok');
subplot(2,1,2);
plot(iteration(2:end), abs_error_list(2:end), '-*b');
hold off;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.