% Program 5.2 % Compound pendulum % Dynamics % Newton-Euler equation of motion % the program uses the function: R(t,x) % the function is defined in the program R.m clear; clc; close; tfinal=10; time=[0 tfinal]; x0=[pi/4 0]; % x(1)(0)=pi/4 x(2)(0)=0 % solve a second order ODE using MATLAB ODE45 function [t,x]=ode45(@R,time,x0); subplot(3,1,1),... plot(t,x(:,1),'r'),xlabel('t'),ylabel('\theta'),grid,... subplot(3,1,2),... plot(t,x(:,2)),xlabel('t'),ylabel('\omega'),grid,... subplot(3,1,3),... plot(x(:,1),x(:,2)), xlabel('\theta'), ylabel('\omega'),grid