clear all sprintf('hello\n'); % ask for terminating time endTime = input('Simulate the Initial Value Problem from time 0 until?: '); % initial conditions time(1) = 0.0; v(1) = 0; s(1) = 0; sp_weight = 70; % constants, Cd is changed to make it same as the coefficient in ODE lecture! g = 9.8; Cd = 10; delta_t = 0.5; % start time/index t = 0.0; i = 2; % the main program while (t < endTime) % update time t = t + delta_t; time(i) = t; % compute velocity v(i) v(i) = v(i-1) + (g * sp_weight - Cd * v(i-1)) / sp_weight * delta_t; % compute distance traveled in m s(i) = s(i-1) + v(i) * delta_t; % update i i = i+1; end % while % output the results side by side % spidey position versus time subplot(2,1,1); plot(time, s); xlabel('Time (s)'); ylabel('S (m)'); title('Spidey''s Position versus Time'); % spidey velocity versus time subplot(2,1,2); plot(time, v); xlabel('Time (s)'); ylabel('Velocity (m/s)'); title('Spidey''s Velocity versus Time');