Week 3 - Solving second order ODEs
CODE 1:ODE SECOND ORDER FUNCTION
clear all
close all
clc
b=0.05;
g=9.81;
l=1;
m=0.1;
%initial values
theta_0=[0;5];
%time points
t_span=linspace(0,10,200);
% ODE
[t,results]=ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
ct=1
for i=1:length(results)
x0=0;
y0=0;
x1=l*sin(results(i,1));
y1=-l*cos(results(i,1));
% plotting
plot([x0,x1],[y0,y1],'linewidth',3);
hold on
plot(x1,y1,'o','markersize',20,'MarkerFaceColor','r')
axis([-2 2 -2 2])
hold off
M(ct)=getframe(gcf)
ct=ct+1;
end
movie(M)
videofile=VideoWriter('ode_simple_pendulum.avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
CODE2:ODE FUNCTION CODE
function [dtheta_dt]=ode_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
ANIMATION OR VIDEO FILE:
https://drive.google.com/file/d/1OjKKgC8ScmxKI5TcHMs8KGKKRondmYiK/view?usp=sharing
EXPLINATION:
AMI: ODE second order function of simple pendulum
THEORY:
Here we are going to discuss about the ode of the second order funtion of the simple pendulum,in that the simple pendulum moves in a oscillation motion and we are creating the function
CODES:
In code 1 we are using the function code ,for loop code to generate code in which the out come will arrive so that we are able to see the animation by using the movie code
And in code 2 the function code which we are going to use in code 1is written in the code 2 as the function code
ANIMATION:
The link which was provide was an animation in that animation we are going to see how the simple pendulum moves when there is a force on it
THE END