Week 4.1 - Solving second order ODEs
Solving second order ODEs
1) Step wise explanation of code.
* Inputs
*Angular velocity
*Entering displacement and velocity
*Solving through ODE 45 function - with function in other file
*Entering 'for' loop
*Creating Animation
https://drive.google.com/file/d/1G72VM7mpDWQyo3rNydzLKrj3CLWlF2cC/view?usp=sharing
Errors :-
Unable to determine scalar and numeric value. Raised Mentoring session to overcome problem.
Screenshot of error.

% program for 2 ODE function.
clear all
close all
clc
%inputs
b=0.05;
m=1;
l=1;
g=9.81;
% angular velocity
theta_0 = [0;3];
% motion
t_span=linspace(0,20,500);
%solve ODE
% ode45 is an inbuilt function, ode_func is elaborating ode45.
[t, result] = ode45(@(t,theta) bode_func(t,theta,b,g,l,m) ,t_span,theta_0);
plot(t, result(:,1))
hold on
plot(t,result(:,2))
amplitude=result(:,1)
%x=[0:5];
ct=1;
for i=1:length(amplitude) %1:length(t_span)
angle=amplitude(i);
title('simple pendulum')
x0=0;
y0=0;
x1=l*sin(angle);
y1=-l*cos(angle);
figure(2)
plot([x0 x1], [y0 y1],'linewidth',3,'color', 'red');
hold on
plot(x1,y1,'o','MarkerSize',20,'MarkerFaceColor',[1 1 0]);
hold on
plot([-1.1 1.1],[0 0],'linewidth',3,'color', 'blue');
axis([-1.5 1.5 -1.5 0.5]);
hold off
grid on;
pause(0.001)
%plot([x0 x1], [y0 y1],'linewidth',3,'color', 'red')
M(ct)=getframe(gcf);
ct=ct+1;
end
movie(M);
videofile=VideoWriter('Aode.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile)
function [dtheta_dt]=bode_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