Challenge

Week 3 - Solving second order ODEs

link for the animation of the pendulam 
https://youtu.be/y6gHr76BF9U


program for the second order differential equations

clear all 
close all
clc
b = 0.05;
g = 9.81;
l = 1
m = 1
% initial condition
theta_0 = [0;5];
% 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);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('plot')
xlabel('time')


ct = 1;
for i = 1:length(ct)
 x1 = l*sin(results(i));
 y1 = -l*cos(results(i));
 plot([x0,x],[y0,y],'line width',2,'color','b')
 hold on
 plot(x1,y1,'o',markersize=20)
 hold off
 axis([-1,1,-1,0]);
 pause(0.1)
 M(ct) = get frame(gcf);
 ct = ct + 1;
end

here,b-damping force
     m-mass
     g-gravity
     l-length
Initial conditions should be theta_0 are given with zero to five ,then apply the ode format to entered the proper syntax using the differential equation codes.then declare the function for the systemtic programming.For creating a motion of a bob using the a formation start with for loop to plot the diagram of tne object motions.

ode_function

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_];
end

function is used to assigning the values of the t,theta,damoing force,mass of the object,length of the pendulam and to evaluate the first order and second order differential equations ,above the line 
dtheta1_dt  : first order derivatives
dtheta2_dt  : second order derivatives of the equation

REPORT:
as the programm writen with the help of matlab having faces different errors on the running time,like to find the value of theta2 the errors are fased because of the mistakes of the syntax error ode format.It could be overcomes with the proper programes are writen.Next one is creating the motion of the pendulam movie formation takes some mistakes are formed because the position are created with (0,180,0).



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.