Question

MATLAB Create an M-File for this IVP, dy/dt = t^2 - 16*sin(t), y(0) = 0 and...

MATLAB

Create an M-File for this IVP, dy/dt = t^2 - 16*sin(t), y(0) = 0 and create an anonymous function g so that it evaluates the slope field at points of our new ODE.

Ensure you use commands of using a for loop to plot the exact solution for the IVP in this exercise as well as the Euler approximations for Δt=0.5, Δt=0.25, and Δt=0.125 all on the same graph.

Homework Answers

Answer #1

% IVP: dy/dt = t^2-16*sin(t), y(0)=0
% it's exact solution is g(t)= t^3/3+16*cos(t)-16
% SOlution by Euler method using N steps

delta_t=0.5; % time step's size
N=10; % number of steps
t(1)=0;
y(1)=0;
g(1)=0;
for n=1:N
y(n+1)= y(n)+delta_t*((t(n)^2/2)-16*sin(n*delta_t));
g(n+1)=(t(n)^3/3)-16*sin(n*delta_t);
t(n+1)=n*delta_t;
end
plot(t,y,'b')
xlabel('t')
ylabel('Numerical and exact values of y')

hold on
plot(t,g,'g')
legend({'numerical ','exact'},'Location','southwest')
hold off

using time stepsize delta_t =0.25, following output

using time stepsize delta_t =0.125, following output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a matlab script file to solve the differential equation dy/dt = 1 − y^3 with...
Write a matlab script file to solve the differential equation dy/dt = 1 − y^3 with initial condition y(0)=0, from t=0 to t=10. matlab question
Are both of the following IVPs guaranteed a unique solution? Explain. (a) dy/dt =y^ 1/3sin(t), y(π/2)=0....
Are both of the following IVPs guaranteed a unique solution? Explain. (a) dy/dt =y^ 1/3sin(t), y(π/2)=0. (b) dy/dt =y^1/3 sin(t), y(π/2)=4.
6. Consider the initial value problem y' = ty^2 + y, y(0) = 0.25, with (exact)...
6. Consider the initial value problem y' = ty^2 + y, y(0) = 0.25, with (exact) solution y(t). (a) Verify that the solution of the initial value problem is y(t) = 1/(3e^(-t) − t + 1) and evaluate y(1) to at least four decimal places. (b) Use Euler’s method to approximate y(1), using a step size of h = 0.5, and evaluate the difference between y(1) and the Euler’s method approximation. (c) Use MATLAB to implement Euler’s method with each...
Write a function M-file my_euler.m which take 5 input values, f, t_0, y_0, dt, and t_f...
Write a function M-file my_euler.m which take 5 input values, f, t_0, y_0, dt, and t_f that specify the function to be approximated, the initial t-value, the initial condition y(t0)=y0, the step-size Δt, and the final t-value at which you want to approximate the solution y(t). Your function should: Use the input anonymous function f to calculate f(t,y). Plot the approximate solution with green "+" symbols at the points and a red line joining them up. Have a function output...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT