Challenge

Week 3 - Solving second order ODEs

The given second degree diffrential equation is:-

where

b is damping coeff.= 0.05

l is lenth of pendulum= 1m

m is mass of ball= 1 kg

g is acceleration due to gravity= 9.81m/s

0 is theta

To sove given equation we need to break it down into first order ODE, by substitution.

let

theta=theta1

so

d(theta)/dt = d(theta1)/dt ...........eq1.

let

d(theta1)/dt=theta2

then

d2(theta)/dt2= d2(theta1)/dt2 =d(theta2)/dt ....... eq2

on subsituting values of eq1 & eq2. in main diffrential eqation, it becomes

d(theta2)/dt= -(b/m)*(theta2)-(g/l)sin(theta1)

now we can write code for the equation below.

%ode variables

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

%initial condition 
theta_0=[0;3];

%time points
[t_span]=linspace(0,20,600);

%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')



where ode_func is 


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

In above code for intial condition we have taken theta to be zero, velocity to be 3m/s, we are calculating values for time span from 0sec to 20sec.

To solve ode we use inbuilt function of matlab i.e ode45.

*errors faced while coding were generaly typographical errors which were over come by re-analysis of code.

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.