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

ME Computational Analysis & Design: HW 4 --Due 10/04 by 10 AM Numerical Root Fin

ID: 3167824 • Letter: M

Question

ME Computational Analysis & Design: HW 4 --Due 10/04 by 10 AM Numerical Root Finding: Part 2 First, do the examples shown in class Write MATLAB codes to find the roots of the following equations. Submit your codes and outputs as a single pdf file to sakai. Be careful! There may be multiple roots. In all problems above, set a tolerance of 108 for convergence. 1. sin(x2)+x2-2x-0.09-0 using Newton's Method, and using MATLAB's fzero function 2. Cos4xv1-x2-8x2 +8x4 +1-0 using Bisection Method to find the brackets, and then Secant Method to find all the roots. So this is like a hybrid method. 3.r6 -3x3+2.25-0 using Newton's Method. How many iterations you need to get a converged result here? Compare this with the number of iterations you got in HW 3 for this problem using Fixed Point iterations (using the same initial guess).

Explanation / Answer

1)

%%% Matlab code %%%

tol=10^(-8);
f=@(x) sin(x^2)+x^2-2*x-0.09;
r=fzero(f,0);
fprintf(' using fzero roots is : %f ',r);
f_=@(x)cos(x^2)*2*x+2*x-2;
x(1)=0;
for n=1:100
x(n+1)=x(n)-feval(f,x(n))/feval(f_,x(n));
if (abs(x(n+1)-x(n)) < tol)
fprintf('Using Newton Raphson method root is : %f ', x(end));
break;
end
end
  

OUTPUT:

using fzero roots is : -0.043139
Using Newton Raphson method root is : -0.043139

2)

%%% Matlab code%%%

tol=10^(-8);
f=@(y) cos(4*y*(1-y^2)^0.5)-8*y^2+8*y^4+1;
%% Bisection to find bracket
a=0;
b=1;
for n=1:10
f1=feval(f,a);
f2=feval(f,b);
if (f1*f2 < 0)
if ( f1 < f2 )
break;
else
k=a;
a=b;
b=k;
end
  
else
b=(a+b)/2;
end
end
fprintf('Bisection method give bracket as [ %f %f ] ',a,b);
y(1)=a;
y(2)=b;
%%% Secant method
for n=2:100
f1=feval(f,y(n));
f2=feval(f,y(n-1));
y(n+1)=y(n)-f1*(y(n)-y(n-1))/(f1-f2);
if ( abs(y(n+1)-y(n)) < tol)
break;
end
end
fprintf('sceant Method ');
fprintf(' roots of equation is = %f ', y(end));
%

OUTPUT:

Bisection method give bracket as [ 0.500000 0.000000 ]
sceant Method
roots of equation is = 0.403973

3)

tol=10^(-8);
f=@(x) x^6-3*x^3+2.25;

f_=@(x) 6*x^5-9*x^2;
x(1)=1;
for n=1:100
x(n+1)=x(n)-feval(f,x(n))/feval(f_,x(n));
if (abs(x(n+1)-x(n)) < tol)
fprintf('Using Newton Raphson method root is : %f ', x(end));
fprintf('Number of iteration required for convergence : %d ',n);
break;
end
end
  

OUTPUT:

Using Newton Raphson method root is : 1.144714
Number of iteration required for convergence : 24