Week 3 - Solving second order ODEs
This is the program, which I have to complete on my own and I don't have a background of programming so I took help from the official site of skill-lync.
There I found program on this I did not just copy and paste it.
Firstly I understand it and then make it.
clear all
close all
clc
%Inputs
b=0.5;
g=9.81;
l=0.5;
m=2;
%Initial condition
theta_0=[0,5];
%Time point
time=linspace(0,10,100);
%ODE Solver
[t,results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),time,theta_0);
plot(t,results(:,1));
hold on
plot(t,results(:,2));
grid on;
%Working of Pendulum
ct=1;
for i=1:length(results(:,1))
x0=0;
y0=0;
x1=l*sin(results(i,1));
y1=-l*cos(results(i,1));
plot([-0.5,0.5],[0,0],'linewidth',3,'color','r');
line([x0 x1],[y0 y1],'linewidth',2,'color','g');
hold on;
plot (x1,y1,'o','markers',20,'markerfacecolor','b');
grid on;
axis([-1.5 1.5 -1.5 0.5]);
pause(0.1);
hold off;
M(ct)=getframe(gcf);
ct=ct+1;
end