%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Compute position and velocity of damped pendulum %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% theta0 = 0.5; % initial position theta_dot0 = -1; % initial velocity tspan = [0 10]; % time boundaries x0 = [theta0;theta_dot0]; global alpha w02 alpha = 1; w02 = 20; [t,x] = ode45('f2',tspan, x0); x1 = x(:,1); x2 = x(:,2); subplot(2,1,1) plot(t,x1); xlabel('time in s'); ylabel('position (rad)'); title('simple damped pendulum'); subplot(2,1,2) plot(t,x2); xlabel('time in s'); ylabel('velocity (rad/s)');