Week 3 - Solving second order ODEs
now, we are going to slove the second order ODE
in the first step the basic program should be type in the editor windoe
and then the input are fed in the program is called geomentry parameters.like, mass, length, damping, gravity.
Ater that the initial condition should be fed into the editor window
the displacement and velocity and also time span also feeded into the initail condition
once the initial condition is over then,
after that open the new file and the fuction to fin (dtheta/dt)
function is used to declare function and input and output. the function of the matlab is procced in the oargram is fed into the the ode program
and then jumping back into the ode program now the fuction is same on the workspace
after that now we are going to find the ode contion
that mean t and output.
(t,output) is required the separate formula
[t,output] = ode45(@(t,theta)ode_pen(t,theta,b,g,l,m),t_span,dis_v)
this is the formula for to find (t, output)
and then the program run is successful then you continue withj plotting.
plotting
plot is ued to connecting the twon line the vector of x,y and of the pendulam is rotating the bar of the revalution the of the pendulam
for code is used for theta,s
for loops is used repaet the loops again and again and for the roataing the movemnt is calculated the angular velocity
and then mark the plotting the figure is placed on the window after that move on to pendular diagram
that is figure 2
in the figure 2 plot the pendular diagram and animated the velocity of the diagram in plot the axis in the graph frame and the linewidth is mension as the required dimension and control the video speed as per the required and end the for programm
and the next process is to create the animation video and same
the same procedure is create the animation program
movie cod eis typed and the after that the video format and place the name for the avi and run program and same on the matlab file
pendulam animation link;
https://drive.google.com/file/d/1NEL_Sl1oBJPg6SVmttDzc7GKCmwutOE3/view?usp=sharing
error

the code is worng i used the lowe case letter
after i uderstand
function [dtheta_dt]=ode_pen(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
%input
l=1
m=0.2
g=9.81
b=0.05
ct=1
%initial condition
dis_v=[0;5]
t_span=linspace(0,20,150);
%ode condition
[t,output] = ode45(@(t,theta)ode_pen(t,theta,b,g,l,m),t_span,dis_v)
figure(1)
hold on
plot(t,output(:,1))
plot(t,output(:,2))
xlabel('x-axis')
ylabel('y-axis')
title('variation of angle displacementamd angular velocity w.r.t time','color','r')
theta2=output(:,1);
for i=1:length(theta2);
theta_x= theta2(i);
x0=0;
y0=0;
y1=-l*cos(theta_x);
%plotting the pendulam
figure(2)
plot([-0.5 0.5],[0 0],'color','b','linewidth',5,'color',[rand rand rand])
hold on
plot([x0 x1],[y0 y1],'color','r','linewidth',2,'color','b')
hold on
plot(x1,y1,'o','markers',15,'markerfacecolor','r')
hold off
grid on
axis([-1.5 1.5 -1.5 0.5]);
pause (0.02)
M(ct)=getframe(gcf)
ct=ct+1
end
movie(M)
videofile=VideoWriter('pendulum.avi','uncompressed avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
my mistake and corrected