Week 3 - Solving second order ODEs
Link- https://youtu.be/OmGawVylRk4
Presentation:-
In this program we try to creat animation video of pendulum motion.Coding contain two tab one is for function and other is for main command.We assume some value like length of pendulum(l), gravitation force, Mass of ball,damping co-efficient etc. theta1 is the angular displacement and theta2 is angular velocity.we take variable 500 between 0 to 10 by using linspace command.For making animation video we use for loop.In for loop,(x0 y0) is initial point that is (0,0). Initial point is fix. we calculate other point (x1,y1), it is varia with respect to time.after that we plot the ball with the help of marker command.
function[dtheta_dt]=ode_func(t,theta,b,g,l,m)
theta1=theta(1)
theta2=theta(2)
dtheta1_dt=theta2;
dtheta2_dt=-(b/m)*theta2-(g/l)*sin(theta1);
dtheta_dt=[dtheta1_dt;dtheta2_dt];
end
clear all
close all
clc
b=0.05;
g=9.81;
l=0.7;
m=0.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),'color','r')
%hold on
%plot (t,results(:,2),'color','b')
ylabel('plot')
xlabel('time')
ct=1
T1=results(:,1);
for i=1:length(T1)
x0=0;
y0=0;
x1=l*sin(T1(i));
y1=-l*cos(T1(i));
plot([x0,x1],[y0,y1],'linewidth',3)
hold on
plot([-0.5 0.5],[0 0],'linewidth',5,'color','black')
plot(x1,y1,'o','MarkerSize',30,'MarkerEdgeColor','red','MarkerFaceColor',[1 .6 .6])
axis([-1 1 -1 0.2])
pause(0.03)
grid on
hold off
M(ct)=getframe(gcf);
ct=ct+1;
end
grid on
movie(M)
Videofile=VideoWriter('second_od.avi','uncompressed AVI');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)