Week 3 - Solving second order ODEs
The code associated with the given programme is as shown:-
clear all
close all
clc
%inputs
b = 0.05;
g = 9.81;
l = 1;
m = 1;
%initial conditions
theta_0 = [0;3];
%time points
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);
%plotting
plot(t,results(:,1))
hold on
plot(t,results(:,2))
xlabel('time')
ylabel('plot')
first the b'g'l'm values are provided as initial values to the insert box.
then the initials conditions are given for the initial position and initial velocity of the bob.
time value is given for 20 seconds.
using ode45 solver we defined the output variables as t and results respectievely,using the ode_func we given the input parameters to the function.
at plotting, the two columns which are observed in results section are plotted which perfectly shows the variation of position and velocity of bob with respect to time.
Errors faced during programming:-
the two scrennshots are attached in browse section which clearly shows the errors obtained.the solution for the first one is that i was executing the function which is not possible as function can only be called in command window.
the solution for the second error is as the function ode_func has to setup by executing edit ode_func in the command window and the error is safely eliminated using this.