Challenge

Week 3 - Solving second order ODEs

% function required for ODE equation 

function [dtheta_dt] = ode_func(t,theta,b,m,l,g)
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
% inputs required for ODE of simple pendulum

b = 0.05;
m = 0.75;
l = 1.5;
g = 9.81;

% in order to define the motion of pendulum we'll need the initial condition of the pendulum 

theta0 = [0;5]   % representing the initial displacment and velocity respentively 

% time period 

t_span = linspace(0,10,500);

% writting ODE equation 

[t,output] = ode45(@(t,theta)ode_func(t,theta,b,m,l,g),t_span,theta0)
 
plot(t,output(:,1),'color','r')
hold on 
plot(t,output(:,2),'color','g')
xlabel('time')
ylabel('values')
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.