Week 3 - Solving second order ODEs
1. Defining input values such as
length of the pendulum(L) = 1m
mass of the bob(m) = 1kg
damping co-efficient(b) = 0.05
Acceleration due to gravity(g) = 9.81m/s^2
2. Initial displacement of the pendulum is zero & intial velocity of the pendulum is 5m/s
3. Time span of the pendulum is between 0 to 20 second goes up to with 600 values.
4. Call ode function include( define ode is the function of t & theta+ ode function include all inputs parametrs +time array[ it means how far integration to be done]+intial condition corresponding to the starting of the time)
5. plot figure 1 in order to determine damping effect in penduum.
6. write down forloop in order to simulate Motion of pendulum. Here give values of hinged point of pendulum, length of thread, diameter of sphere and others x & y co-ordinates of the pendulum structure.
7. Give 'getframe' command in order to capture the photos. Also, 'M' command to store the images.
8. finally , Movie program come into the picture in order to make a video.
insted of this, in order to eliminate a error i have been correct the file name of the file as 'ode_func' . first it was wrote by me is 'ode_function' .
close all
clear all
clc
%inputs
L = 1; %m
m = 1; %kg
b = 0.05;
g = 9.81; %m/s^2
% initial condition
theta_v = [0;3];
% time points
t_span = linspace(0,15,600);
% solve ODE
[t,results] = ode45(@(t,theta) ode_func(t,theta,L,m,b,g),t_span, theta_v);
figure(1)
plot(t,results(:,1));
hold on;
plot(t,results(:,2));
xlabel('Time(sec)');
ylabel('Angular displacement & Angular veocity');
grid on
title('Damping effect in pendulum');
legend('Angular displacement','Angular velocity');
ct = 1
for i = 1:length(t_span);
x0 = 0;
y0 = 0;
%x1 = L*sin(results(i,1))
x1 = 1*sin(results(i,1));
%y1 = L*cos(results(i,1))
y1 = -1*cos(results(i,1));
figure(2)
plot([x0 x1],[y0 y1],[-0.7 0.7],[0 0],'linewidth',5)
hold on
plot(x1,y1,'marker','o','markerSize',20,'markerfacecolor','r')
axis([-1.5 1.5 -1.5 0.5]);
grid on
title('Motion of Pendulum');
%get frame command for movie frame.
M(i) = getframe(gcf);
hold off
end
movie(M)
Videofile = VideoWriter('Pendulum.avi','Uncompressed AVI')
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)
Here si My youtube video link:-
https://youtu.be/NBLFNuPi9yg