Question: The exact solution is y = t^2 + 4exp (-t^2 / 2) - 2. I need help plugging this in the yExact section of the

The exact solution is y = t^2 + 4exp (-t^2 / 2) - 2. I need help plugging this in the yExact section of the code!!

Apply the Euler method to solve dy/dt = -t y + t^3; y(0) = 2 from t =0 to t = 2. Cut and paste the above snippet of code into the MATLAB editor. Modify as necessary and save it as a .m file in order to do the following: Compute the exact solution and use your program to do the following: Figure out what is the minimum value of N that you need to get an error smaller than 0.01 at the final time. Do this by experimenting with N until you get a small enough error. Plot the computed and exact solution using this value of N. Show the method is approximately second order by doubling N and computing the ratio of the errors.

We are given a sample code and are supposed to copy paste the code with just a few modifications. I have tried various codes but none seem to be working. I was hoping I could get a help from here.

P.S. the code given below is correct for dy/dt = sin ty , y(0) = 1

N = 200; h=tFinal/N; t=linspace(0,tFinal,N+1); % type 'help linspace' to see how this works y=zeros(1,N+1); yExact=exp(1-cos(t)); y(1) = 1; % setting the initial condition for n=1:N y(n+1) = y(n) + h * sin(t(n))*y(n); end plot(t,y,t,yExact,'--') xlabel('t'); ylabel('y'); title('Look, ma! I solved another ODE in MATLAB!'); error200= abs(y(N+1)-yExact(N+1)); fprintf('The error went down by a factor of %f. ',error100/error200); 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!