Week 3 - Solving second order ODEs
The fig and programm shows the ordinary differential equation.the programm for solving the ordinary differential equation.we first convert the second order function into first order equation.Because the matlab cannot solve the 2nd order diff equation.
ODE45 is the matlab function which is use to solve the ode in MATLAB.
FIG=ORDINARY DIFFERENTIAL EQUATION.

FIG=SIMPLE PENDULUM
PROGRAM TO SOLVE ORDINARY DIFFERENTIAL EQUATION.
clear all
close all
clc
ct=1;
b=0.5;
g=9.81;
l=1;
m=1;
% initial condition
theta_0=[0;5];
% time points
t_span=linspace(0,10,500);
% solve ODE
[t,results]=ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('plot')
xlabel('time')
theta =results(:,1);
ct=1;
for i=1:length(theta)
Theta=theta(i);
%initial points
x0=0;
y0=0;
% movement of pendulum
x1=l*sin(Theta);
y1=-l*cos(Theta);
figure(2);
%plotting string
plot([x0 x1],[y0 y1],'Color','g');
hold on
%plotting pendulum bob
plot(x1,y1,'o','markersize',10,'Color','r','MarkerFaceColor','r');
hold off
axis([-1 1 -1.5 0]);
pause(0.03);
M(ct)= getframe(gcf);
ct=ct+1;
end
% creating a movie
movie(M);
videofile=VideoWriter('pendulum.avi','Uncompressed avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
fig shows the ordinary differential equation.

fig=ODE
we first convert the second order function into first order equation.Because the matlab cannot solve the 2nd order diff equation.
ODE45 is the matlab function which is use to solve the ode in MATLAB.