Challenge

Week 3 - Solving second order ODEs

simple pendulam working on the newtons law

the pendulam has been the second oder function,that can be spit into 2 parts

by considering the dimensions of pendulam,

g= acceleration due to gravity

=9.81

l= length of the pendulam

=1

m= mass of the pendulam

=0.1

b = 0.05

in a initial conditon theta _0 is changing from o to 5

theta_0 = [0;5]

time can change from the o to 10 with in the 500 values

t_span+ linspace (0,10,500)

by solving the second ode function of thr simple pendulam

[t,results]=ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_spam,theta_0)

in a ode function can spit in to 2 parts

theta1 and theta2

by creating the function of the doe,

[dtheta-dt]= ode_func(t,theta,b,g,l,m)

theta1= theta(1)

theta2= theta(2)

dtheta1_dt = -(b/m)*theta2 -(g/l)*sind(theta1);

dtheta_dt = [dtheta1_dt; dtheta2_dt]

when making the plot for the movement of pendulam '

plot(t,resuits(:,1)

plot(t,results(:,2)

we got a graph ,when the changing the initial condion and the time of the pendulam in asame coding and adding the dispacement

theta_0 = [0:3]

t_spam = linspace(0,20,500)

displacement = results:,1)

making the figure 2 of the pendulam

plot([-0.5,0.5],[0,0],'-','line width',3,'color','b')

plot([x0,x1],y0,y1],'linewidth',3,'color','r')

plot9[x1,y1,'o',Markersize',20,'markerfacecolor','r')

axis([-1.5 1.5 -1.5 0.5])

for making the animation of the figure2 s ,

pause the vidoe in a0.003seconds

pause(0.003)

for the vidoe can be making by using the videowriter command

in a compressed avi form

opne and close the animation video by using '

open(videofile)

close (videofile)

the animation video can upload in the youtube

the animation link is;

https://youtu.be/9_Ape0lr38l

clear all
close all 
clc

b=0.05;
g=9.81;
l=1;
m=0.1;

%initial contitoin
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);

 plot(t,results(:,1)) 
 hold on
 plot(t,results(:,2))
 ylabel('plot')
 xlabel('time') 


ode function;

  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)*sind(theta1);
    dtheta_dt=[dtheta1_dt; dtheta2_dt];
end



changing the above codig

clear all
close all
clc

b=0.05;
g=9.81;
l=1;
m=0.1;

%initial contitoin
theta_0=[0;3]  %initial angular displacement=0 angular velocity=3rad/sec

%time point
t_span=linspace(0,20,500);

%solve ode
[t,results]=  ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);

displacement=results(:,1)


%ploting results

figure(1)
hold on
plot(t,results(:,1))
plot(t,results(:,2))
ylabel('plot')
xlabel('time')

%animation
%initial condition
 x0=0;
 y0=0;
 ct=1
for i=1:length(displacement)
    THETA1=displacement(i);
    x1=1*sind(THETA1);
    y1=-1*cosd(THETA1);

figure(2)
 plot([-0.5,0.5],[0,0],'-','linewidth',3,'color','b')
 hold on
 plot([x0,x1],[y0,y1],'linewidth',3,'color','r')
 hold on
 ylabel('plot')
 xlabel('time')
 plot(x1,y1,'o','Markersize',20,'MarkerFaceColor','r')
 hold off
 axis([-1.5 1.5 -1.5 0.5]);
 pause(0.003)

 M(ct)=getframe(gct)
 ct=ct+1;

end

videofile=VideoWriter('pendulam.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

 
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.