% function [x, yE] = odeEU_student(ODE,a,b,h,y0)% Variable InitializationN = (b-a)/h;yE=zeros(1,N+1);t=zeros(1,N+1);% Initial ConditionyE(1) = y0;t(1)=a;% Euler Explicit ODE Methodfor i = 1:N% Calculate: t(i+1)=_________% [TO-DO] your code goes here% Estimate: yE(i+1)=________% [TO-DO] your code goes here end% end % End of Function
Exercise 1: Euler's Explicit Method for 2nd-order ODE
sys2EU_student.m
First, fill-in this blank and complete the algorithm
% function [t, yE, vE] = sys2EU_student(gradF,a,b,h,yINI, vINI)% Variable Initialization N = (b-a)/h; t=zeros(1,N+1); yE=zeros(1,N+1); vE=zeros(1,N+1);% Initial Condition yE(1) = yINI; vE(1) = vINI; t(1)=a;% Euler Explicit ODE Methodfor i = 1:N t(i+1) = t(i) + h; dYdt=gradFunc_mck(t(i),[yE(i),vE(i)]);% Estimate: yE(i+1)=________% [TO-DO] your code goes here % Estimate: vE(i+1)=________% [TO-DO] your code goes here end% end % End of Function
Then, create the function file as sys2EU_student.m
[t, yE, vE] = sys2EU_student(@gradFunc_mck,a,b,h,yINI, vINI);
Exercise 2: 2nd order Runge-Kutta for 2nd-order ODE