function [void] = RK2Solver(n, v, H, L, mult) %RK2Solver(n, v, H, L, mult) % %n determines the runga-kutta interval (smaller n means better estimation) %v is the velocity of the car %H is the height of the bump %L is the length of the bump %mult determines the amount of time we want the plot to cover (usually 5) %interval over which y is evaluated is mult*length of bump (in time) omegaN=sqrt(9.8/.3); alpha=sqrt(2)/2*omegaN; deltaT=L/v; h=mult*deltaT/n; t=0; Y=[0;0]; tresult = zeros(1,n)'; xresult = zeros(1,n)'; yresult = zeros(1,n)'; ydotresult = zeros(1,n)'; result=[tresult xresult yresult ydotresult]; for I = 2:n if(I<(n/mult)) x=xfunct(t,H,deltaT); xdot = xdotfunc(t,H,deltaT); else x=0; xdot=0; end V1=vfunc(Y,x,xdot,omegaN,alpha); Ytemp=Y+h*V1; t=t+h; V2=vfunc(Ytemp,x,xdot,omegaN,alpha); Y=Y+(V1+V2)/2*h; result(I,1)=t; result(I,2)=x; result(I,3)=Y(1,1); result(I,4)=Y(2,1); end % figure(1) % plot(result(:,1),result(:,2)) % title('Vertical Displacement of Road vs. Time'); % ylabel('x(t) (m)'); % xlabel('time (s)'); figure(2) plot(result(:,1),result(:,3)) title(sprintf('Y (Runge-Kutta) road: H=%f L=%f V=%f', H, L, v)); ylabel('y(t) (m)'); xlabel('time (s)');