Week 3 - Solving second order ODEs
%second order ode
%input values
b = 0.05
l = 0.2
g = 9.81
m = 0.2;
%initial condition
theta_initial = [0,5];
%time spsn
t_span = linspace(0,100,500);
%solve ode
%[t,result] = ode45(@(t,theta) ode(t,theta,b,g,l,m),t_span,theta);
[t,theta] = ode45(@(t,theta) ode_value(t,theta,b,g,l,m),t_span,theta_initial);
plot(t,theta)
function program:
function [dtheta_dt] = ode_value(t,theta,b,g,l,m)
theta1 = theta(1)
theta2 = theta(2)
dtheta_dt = [theta2; -(b/m)*theta2-(g/l)*sin(theta1)]
end
The second order differential equation :
The progrsm stsrts with the initial given cindition. Time span is choosen to iniciate the time diruation of the curve. Plotting the given data with the help of "Function" command.