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

Mathematical Methods for Electrical Engineers (EEE 3US: HW Q1 Find the root of t

ID: 3184187 • Letter: M

Question

Mathematical Methods for Electrical Engineers (EEE 3US: HW Q1 Find the root of the following function considering the interval [0, 2]: ()CS()sin () by using: a) Bisection Method, b) Newton's Method, and c) Fixed-Point Iteration Method. In this homework, you are expected to .provide calculations of the first 2 iterations for each method write a MATLAB code that calculates the root for each method, .comment on the convergence speed. To check for the convergence, use Epsilon-0.000001, and stop if |(Knl -Xm)

Explanation / Answer

%function c=bisec(a,b)
f=@(x)(cos(x)*sin(x)/2)-x+1;
a=0;
b=2;
eps_abs = 1e-5; % tolerence
eps_step = 1e-5;
n=0;
while (b - a >= eps_step || ( abs( f(a) ) >= eps_abs && abs( f(b) ) >= eps_abs ) )
    c = (a + b)/2 % midpoint
    if ( f(c) == 0 )
       break;
    elseif ( f(a)*f(c) < 0 )
       b = c;
    else
       a = c;
    end
    n=n+1;
end
c
n

% Answer

c =

   1.177116394042969


c =

   1.177116394042969


n =

    18

%Newton

clc;
clear all;

f=@(x)(cos(x)*sin(x)/2)-x+1;;%function

f1=@(x)(cos(2*x)/2)-1; %derivative of function


x0=0.9;%initial guess
n=0;
erorr=0.1;
del=1e-6;
x(1)=0.9;
m=2;
while (abs(erorr>del)& (n<=100))
y1=x0-(f(x0)/f1(x0));% Newton method

erorr(n+1)=abs((y1-x0)); %erorr

% if abs(erorr<1e-3)
% break
%end
n=1+n;
x0=y1;
x(n+1)=x0;
end
disp('Root is')
x(end)
disp('num_iter          x_value                erorr')
disp('_______________________________________________________________________________')
for i=1:n
fprintf('%d %20f %20f ',i ,x(i),erorr(i))

end

Root is

ans =

   1.177121379111391

num_iter          x_value                erorr
_______________________________________________________________________________
1                  0.900000                  0.308425
2                  1.208425                  0.031061
3                  1.177363                  0.000242
4                  1.177121                  0.000000

%fixed

clc;
clear all;
f=@(x)(cos(x)*sin(x)/2)+1;
x0=0.9;
del=1e-6;% tolerance
err=0.1;
n=0;
while(err>del)
    y2=f(x0);
    err(n+1)=abs(x0-y2);
    x0=y2;
    n=n+1;
    x(n+1)=x0;
end
n

disp('num_iter          x_value                erorr')
disp('_______________________________________________________________________________')
for i=1:n
fprintf('%d %20f %20f ',i ,x(i),err(i))
end

n =

    13

num_iter          x_value                erorr
_______________________________________________________________________________
1                  0.000000                  0.343462
2                  1.243462                  0.091238
3                  1.152224                  0.033459
4                  1.185684                  0.011609
5                  1.174074                  0.004119
6                  1.178193                  0.001451
7                  1.176743                  0.000512
8                  1.177255                  0.000181
9                  1.177074                  0.000064
10                  1.177138                  0.000022
11                  1.177116                  0.000008
12                  1.177123                  0.000003
13                  1.177121                  0.000001
>>

%Note , we can obesrve that neton method number of iteration n=4 , therefore Newton method is convergence fast