Differential equation of simple pendulum
d^2θ /dt^2 + (g/L)*sin(θ )=0
Initial conditions: θ(0) = θ0 , θ'(0) = 0
The angular displacement θ0 = 30 degrees, length of the pendulum L = 0.6 m and gravity g = 9.82 m/s^2.
This is the script I use to solve the differential equation with ode45 and to plot the solution in degrees but I got a wrong plotting.
theta0=30;L=0.6;g=9.82;t=0:100;[t,theta30]=ode45(@(t,THETA) fun(t,THETA,g,L),t,[theta0*pi/180 0]);plot(t,theta30(:,1)*180/pi,'--b')grid onaxis ([0 t(end) -30 30])xlabel('Time')ylabel('Angle')function dthetadt=fun(t,THETA,g,L)dthetadt=zeros(2,1);dthetadt(1)=THETA(2);dthetadt(2)=(-g/L)*sin(THETA(1));end
Best Answer