%Main function %Assign values to parameters m=1; c=0; k=4; %Give initial conditions z0=[1; 0]; %Give the time interval to compute the solution tspan=[0 100]; %Solve for the solution of the initial value problem using ode45 from %Matlab options=odeset('RelTol',1e-5,'AbsTol',1.e-5); [t,z]=ode45('fcnspring',tspan,z0,options,m,c,k); %Plot the solutions figure(1) plot(t,z(:,1),'b-*',t,z(:,2),'r-v') grid on xlabel('Time') ylabel('Displacement and Velocity') title('Spring-Mass-Dashpot System Solution') legend('Displacement','Velocity',0) %Plot the solution and the forcing function figure(2) forcing=sin(2*t); plot(t,z(:,2),'b-*',t,forcing,'r-v') grid on xlabel('Time') ylabel('Displacement and Forcing Function')