Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE I need help in MATLAB problem Background and formulation of the problem R

ID: 3601960 • Letter: P

Question





PLEASE I need help in MATLAB problem

Background and formulation of the problem Root finding is a classic computational mathematical problem, and very often of high interest to engineers. This is especially true when one cannot calculate analytically the roots of a merical algorithm for r Raphson. Let f:CC be continuously differentiable, and a point zn E C to be an initial estimate of the root. The next estimate of the root will be, f(zn) which is known as the Newton-Raphson formula. Usually after enough iterations the algorithm will provide a good approximation of the root of f. Of course, one would need to

Explanation / Answer

x = 0.05;
x_old = 100;
x_true = 0.0623776;
iter = 0;
while abs(x_old-x) > 10^-3 && x ~= 0
x_old = x;
x = x - (x^3 - 0.165*x^2 + 3.993*10^-4)/(3*x^2 - 0.33*x);
iter = iter + 1;
fprintf('Iteration %d: x=%.20f, err=%.20f ', iter, x, x_true-x);
pause;
end

m0=.75*ones(length(x),1);
m1=m0+.25*x;
m2=m1-2*x .^2;
m3=m2+x .^3;
% plot McLaurin series
f1=figure;
plot(x,m0, x,m1,’:’, x,m2, ’-.’, x,m3, ’--’)
l=legend(’Zero Order’,’First Order’,’Second Order’,’Third Order’);
set(l,’FontSize’, 16);
set(gca, ’FontSize’,16);
xlabel(’x’, ’Fontsize’,16);
ylabel(’f(x)’, ’Fontsize’,16);
title(’McLaurin Series’, ’Fontsize’,16)
% find Taylor series
t0=0*ones(length(x),1);
t1=.75*ones(length(x),1)-.75*x;
t2=1.75*ones(length(x),1)-2.75*x+x .^2;
t3=.75*ones(length(x),1)+.25*x-2*x.^2+x.^3;
% plot Taylor series
f2=figure;
plot(x,t0, x,t1,’:’, x,t2, ’-.’, x,t3, ’--’)
l=legend(’Zero Order’,’First Order’,’Second Order’,’Third Order’);
set(l,’FontSize’, 16);
set(gca, ’FontSize’,16);
xlabel(’x’, ’Fontsize’,16);
ylabel(’f(x)’, ’Fontsize’,16);
title(’Taylor Series’, ’Fontsize’,16)

% Newton-Raphson method solution for x^3-2x^2+0.25x+0.75=0
% form x and f(x)
x=-5:.05:5;
x=x(:);
t3=.75*ones(length(x),1)+.25*x-2*x.^2+x.^3;
xn=-5;
xo=10;
% final error criterion
e=.0001;
% plot the function
f2=figure;
2=figure;
8
fx=xn^3-2*xn^2+.25*xn+.75;
plot(x,t3, ’--’, xn, fx, ’s’)
set(gca, ’FontSize’,16);
xlabel(’x’, ’Fontsize’,16);
ylabel(’f(x)’, ’Fontsize’,16);
set(gca, ’XTick’, -5:.5:5);
title([’Newton-Raphson Method (from ’, num2str(xn), ’)’], ’Fontsize’,16)
grid on
hold on
% do the iteration until convergence
while abs((xn-xo)/xn) > e
fx=xn^3-2*xn^2+.25*xn+.75;
fpx=3*xn^2-4*xn+.25;
xn=xn-(fx)/(fpx);
plot(xn, fx, ’s’);
pause
end
%----------------------------------------
% Bisection method solution for x^3-2x^2+0.25x+0.75
% form x and f(x)
x=-5:.05:5;
x=x(:);
t3=.75*ones(length(x),1)+.25*x-2*x.^2+x.^3;
% initial range
xo=10;
e=.0001;
xl=-4.5;
xu=5;
xn=(xl+xu)/2;
% plot f(x) and current solution
f2=figure;
fx=xn^3-2*xn^2+.25*xn+.75;
fxl=xl^3-2*xl^2+.25*xl+.75;
fxu=xu^3-2*xu^2+.25*xu+.75;
plot(x,t3, ’--’, xn, fx, ’s’, xl, fxl, ’<’, xu, fxu, ’>’)
set(gca, ’FontSize’,16);
xlabel(’x’, ’Fontsize’,16);
ylabel(’f(x)’, ’Fontsize’,16);
set(gca, ’XTick’, -5:.5:5);
title([’Bisection Method (between ’, num2str(xl), ’ and ’, num2str(xu), ’)’], ...
’Fontsize’,16)
grid on
9
hold on
if (fxl*fx <=0)
xu=xn;
elseif (fxu*fx <=0)
xl=xn;
else
return;
end
% iteratively improve the range and find the solution
while abs((xn-xo)/xn) > e
fxl=xl^3-2*xl^2+.25*xl+.75;
fxu=xu^3-2*xu^2+.25*xu+.75;
xo=xn
xn=(xl+xu)/2
fx=xn^3-2*xn^2+.25*xn+.75;
if (fxl*fx <=0)
xu=xn;
elseif (fxu*fx <=0)
xl=xn;
else
break
end
plot(xn, fx, ’s’, xl, fxl, ’<’, xu, fxu, ’>’);
pause
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote