Week 3 - Solving second order ODEs
close all
clear all
clc
b =0.05;
g=9.81;
m=0.1;
l=0.5;
%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);
% ploting
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('plot')
xlabel('time')
%for loop
ct =1
for i = 1:length(results(:,1));
x_start = 0;
y_start = 0;
x_end = l*sin(results(i,1));
y_end = -1*cos(results(i,1));
% plotting the animation
figure(2)
plot([-1 1], [0 0], 'linewidth',3)
hold on
plot([x_start x_end],[y_start y_end],'LineWidth',2)
hold on
plot(x_end,y_end,'o','markersize',10,'color','r')
title('Animation of pendulum')
axis([-1.5 1.5 -1.5 1])
pause(0.05)
hold off
M(ct) = getframe(gcf);
ct = ct+1;
end
% animation of pendulum
movie(M)
videofile=VideoWriter('Pendulam Animation.avi', 'uncompressed avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
i have many doutes faced in this program . i have taken a technical supportes help to solve this coding.
