Week 3 - Solving second order ODEs
SECOND ORDER DIFFRENTIAL EQUATION
STEPS INVOLVE:
- intialisation of variable required for seconf order differential eqn i.e theta , time,length of string,mass of ball,force of gravity ,damping coefficient.
- defining function with name ODE which input argument theta and time and sovle the sencond order diffrential eqn and returns the dispalcement(positionn of ball) and angular velocity of ball with respect to time as an array.
- ploting the graph between time VS displacement and time Vs angular velocity.
- simulation of pendulumn by tracing its angular position with respect time in plot.
- saving the images at each interval of time.
- stitching all the images into video form with the hep of magick tool in cmd prompt.
Video of second output
%initial condition
theta0=[0;3];
%time array
time=linspace(0,20,500);
%solve ode using lsode function in octave
[result] = lsode('ODE',theta0,time);
% dispacement of pendulam
disp=result(:,1);
%angular volcity of pendulam
angvlcty=result(:,2);
%plotting 1st plot between time ,displacement and angular velocity
figure(1)
plot(time,disp,'color',[0.3 0.3 0.3]);
hold on
plot(time,angvlcty,'color',[0.6 0.50 0.2]);
xlabel("time-->");
ylabel("displacement & angular velocity-->");
hold off;
%for simulation
ct=1;
for i=1:length(disp);
x0=0;
y0=0;
THETA1=disp(i);
x1=l*sin(disp(i));
y1=-(l*cos(disp(i)));
%plotting simulation of pendulum
figure(2)
plot([-1,1],[0 0],'linewidth',4,'color','k')
hold on;
plot([x0 x1],[y0 y1],'linewidth',3,'color','b');
hold on ;
plot(x1,y1,'-o','markers',20,'markerfacecolor','r');
axis([ -1.5 1.5 , -1.5 1.5]);
hold off;
pause(0.00003)
text=sprintf('output%d.png',ct)
saveas(gca,text);
ct=ct+1
end
2)second function
function [d_theta]= ODE(theta0,t)
b=0.05;
g=9.81;
l=1;
m=0.1;
theta1=theta0(1);
theta2=theta0(2);
d_theta1=theta2;
d_theta2=-(b/m)*theta2-(g/l)*theta1;
d_theta=[d_theta1 d_theta2]
endfunction
1st output
3)Problem during whole process
problem i faced during the process is "horizontal dimension mismatched" during the simuation of pendulumn
screenshot
how i resolved the problem
i resolved the problem with the help of your experts during the support session.