Week 3 - Solving second order ODEs
AIM : To solve second order ODE programme in which showing motion of pendulum
clear all
close all
clc
% Inputs
b = 0.05
g = 9.81
l = 1
m = 1
OBJECTIVE:
To simulate the motion between 0-20 sec,at time t = 0, angular displacement = 0, angular velocity = 3 rad/sec.
% function
function [dtheta_dt] = ode_fun(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; dtheta_2dt];
end
% main programme
theta_0 = [0;3];
t_span = linspace(0,20,50);
[t,result] = ode45(@(t,theta) ode_fun(t,theta,b,g,l,m),t_span,theta_0)
ct = 1
for 1 = 1:length(result);
x0 = 0;
y0 = 0;
x1 = l*sin(result(i,1));
y1 = l*cos(result(i,1));
figure(1)
plot([-0.5, 0.5],[0,0])
hold on
plot ([x0,x],[y0,y])
hold on
plot(x,y,'marker','.','markersize',50)
axis([-2 2, -2 2])
ct = ct+1,
hold off
end
LEAVE A COMMENT
Thanks for choosing to leave a comment . Please keep in mind that all comments are moderated according to our comment policy and your email address will not published. Lets have a personal and meaningful conversation.