function Lab2_ODE_solver_near_res % This file applies to: % Question 5 - be careful to set b=0 % Question 8 - be careful to set b as requested in the lab function dy=myODE(t,y) % k - spring constant % m - mass % Frequency om=sqrt(k/m) dy1=y(2); dy2=-om^2*y(1)-b*y(2)+cos(om0*t); dy=[dy1;dy2]; end % initial conditions y0=[5; 0]; % time interval t=0:1:100; %natural frequency om=1; %forcing frequency om0=1.005; %damping b=0; [t,y1]=ode45(@myODE, t, y0); %%%%%% Trying with different parameters %natural frequency om=1; %forcing frequency om0=1.5; %damping b=0; [t,y2]=ode45(@myODE, t, y0); %%%% A plot comparing the two solutions plot(t,y1(:,1),'-', t,y2(:,1),'--') legend('displacement, om=1, om0=1.005', 'displacement, om=1, om0=1.5') end