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

fix the bisection code in Matlab below and obtain the value Y(1)=0.4962 Using th

ID: 3833696 • Letter: F

Question

fix the bisection code in Matlab below and obtain the value Y(1)=0.4962 Using the following code:

MATLAB CODE:

(1) =0.4962; % Can you fix the code below to obtain this boundary condition?

Y(2) = 0.; Y(3) = 0.;

Y_t = [Y(1); Y(2); Y(3)];

n = 1000; % # of steps
d_eta = 1.e-2; % step size, eta_max = d_eta * n
eta=0.;
for i=1:n
%---------- First Stage -----------%
R_1 = [-Y(1)*Y(3) Y(1) Y(2)];
Y_1 = d_eta*R_1;
%---------- Second Stage -----------%
R_2 = [-(Y(1)+0.5*Y_1(1))*(Y(3)+0.5*Y_1(3)) Y(1)+0.5*Y_1(1) Y(2)+0.5*Y_1(2)];
Y_2 = d_eta*R_2;
%---------- Third Stage -----------%
R_3 = [-(Y(1)+0.5*Y_2(1))*(Y(3)+0.5*Y_2(3)) Y(1)+0.5*Y_2(1) Y(2)+0.5*Y_2(2)];
Y_3 = d_eta*R_3;
%---------- Fourth Stage -----------%
R_4 = [-(Y(1)+Y_3(1))*(Y(3)+Y_3(3)) Y(1)+Y_3(1) Y(2)+Y_3(2)];
Y_4 = d_eta*R_4;
  
Y = Y + (Y_1 + 2*Y_2 + 2*Y_3 + Y_4)/6;
  
eta = [eta d_eta*i];
Y_t = [Y_t Y'];
end

BISECTION METHOD MATLAB CODE
%-------------Using Bisection method---------%
xl = 0.1;
xu = 1;
%Initial Approximation
xm = (xl+xu)/2;
%Inital error
ea = 100;
while Y_t(2,end)>0.0000001
if Y_t(2,end)<0
xl=xl;
xu=xm;
xmold=xm;
else if Y_t(2,end)>0
xl=xm;
xu=xu;
xmold=xm;
else
disp(xm)
end
xm = (xl+xu)/2;
ea = (abs(xm-xmold)/xm)*100;
end
end

Explanation / Answer

xl = 0.1;
xu = 1;
%Initial Approximation
xm = (xl+xu)/2;
%Inital error
ea = 100;
while Y_t(2,end)>0.0000001
if Y_t(2,end)<0
xl=xl;
xu=xm;
xmold=xm;
else if Y_t(2,end)>0
xl=xm;
xu=xu;
xmold=xm;
else
disp(xm)
end
xm = (xl+xu)/2;
ea = (abs(xm-xmold)/xm)*100;
end
end