Question: Please answer with MATLAB Code. Thanks... Solve the ODE from Q1 with your euler2 function for the cases where h= 0.1, h = 0.3, h
Please answer with MATLAB Code. Thanks...
Solve the ODE from Q1 with your euler2 function for the cases where h= 0.1, h = 0.3, h = 0.5. You should use a for loop to loop through the different h values. Plot the three solutions in the same figure as the solution you got from Q1.
apply_ode45 - From Question 1:
function [TOUT,YOUT] = apply_ode45()
tspan = [0 1];
y0 = 0;
[TOUT, YOUT] = ode45(@(t,y) 8.85-1.26*y^2, tspan, y0);
end
euler2 Function:
function [TOUT,YOUT] = euler2(ODEFUN,TSPAN,Y0,h)
t=TSPAN(1);
i=1;
TOUT(1)=t;
YOUT(1)=Y0;
tlim=TSPAN(2);
while t < tlim
i=i+1;
m=ODEFUN(t,Y0);
if (t+h)>TSPAN(2)
h=h-(t+h-TSPAN(2));
end
y=Y0+h*m;
t1=t+h;
TOUT(i)=t1;
YOUT(i)=y;
t=t1;
Y0=y;
end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
