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

Coding must be done in MATLab 4) (13 pts) Forward/Backward Euler a(3) Write a ge

ID: 3872576 • Letter: C

Question

Coding must be done in MATLab

4) (13 pts) Forward/Backward Euler

a(3) Write a general-purpose Forward Euler function (it should take a function handle for calculating the derivative, initial x value, final x value, initial y value, and step size as inputs). Assume that dy/dx is only a function of y.

b(3) Write a general-purpose Backward Euler function (it should take the same inputs as above, but use root finding to solve the implicit equation – you may use the Secant code that I've posted on KSOL to perform this). Note: you can call functions from within functions, and you can absolutely create a function handle that uses another function handle. For the next two problems (c&d), use the following: dy/dx = (-7)y; y0 = 10, over the interval [0,1].

c(3) Investigate the stability we discussed in class by choosing different “h” values – you have freedom here. Find at least three different types of behavior for the Forward Euler method, and plot them.

d(2) Plot the same step sizes with Backward Euler. Compare the behavior (using words).

e(2) Compare the computation time (using numbers and words).

Bisection.m code

%%-------------------Bisect.m--------------------------------------

function [bisect]= Bisect(xl,xu,es,imax,xr,iter,ea)
iter=0;

while ( (ea > es) | (iter<=imax))
xrold=xr;
xr=(xl-xu)/2;
iter=iter+1;
if(xr~= 0)
ea=abs((xr-xrold)/xr) *100;
end
test=f(xl)*f(xr);
if (text>0)
xl=xr;
else
ea=0;
end
end
bisect=xr;

%----------------------------------------------------------------------------------

%%-------------------------f.m---------file to define your function--------------------------

function f=f(x)
f= x^10 - 10*x^5 +0.4*x - 0.4;

Explanation / Answer

function [bisect]= Bisect(xl,xu,es,imax,xr,iter,ea)
iter=0;
while ( (ea > es) | (iter<=imax))
xrold=xr;
xr=(xl-xu)/2;
iter=iter+1;
if(xr~= 0)
ea=abs((xr-xrold)/xr) *100;
end
test=f(xl)*f(xr);
if (text>0)
xl=xr;
else
ea=0;
end
end
bisect=xr;

function f=f(x)
f= x^10 - 10*x^5 +0.4*x - 0.4;

function [bisect]= Bisect(xl,xu,es,imax,xr,iter,ea)
iter=0;
while ( (ea > es) | (iter<=imax))
xrold=xr;
xr=(xl-xu)/2;
iter=iter+1;
if(xr~= 0)
ea=abs((xr-xrold)/xr) *100;
end
test=f(xl)*f(xr);
if (text>0)
xl=xr;
else
ea=0;
end
end
bisect=xr;
function f=f(x)
f= x^10 - 10*x^5 +0.4*x - 0.4;  

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