Week 3 - Solving second order ODEs
https://drive.google.com/file/d/1taO2MbZItPHZ5CrOM3dLbdDzcOCdYYhn/view?usp=sharing
I had completed my program and done the animation successfully and generated a lik and uploaded above.
PROGRAM FOR SECOND ORDER ODE:
clear all
close all
clc
b = 0.05;
g = 9.81;
l = 1;
m = 0.1;
%initial condition
theta_0 = [0;5];
%time points
t_span = linspace(0,10,500);
%solve ODE
[t, results] = ode45 (@(t,theta) ode_function(t, theta, b , g, l, m), t_span, theta_0);
disp = results(:,1);
vel = results(:,2);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('plot')
xlabel('time')
figure(2)
x0 = 0;
y0 = 0;
ct = 1;
for i = 1:length(disp)
x1 = 1*sin(disp(i,1));
y1 = -1*cos(disp(i,1));
plot([x0 x1] ,[y0 y1])
hold on
plot(x0,y0,'s','Markersize',10)
plot(x1,y1,'.','Markersize',50)
axis([-2 2 -2 2])
pause(0.1)
hold off
M(ct)=getframe(gcf)
ct = ct+1
end
movie(M)
videofile = VideoWriter('pendulum.avi');
open(videofile)
writeVideo(videofile, M)
close(videofile)
--------------------------------------------------------------------------------------------------------------------------------------------
FUNCTION FOR THE ABOVE PROGRAM:
function [dtheta_dt] = ode_function(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_dt];
end
--------------------------------------------------------------------------------------------------------------------------------------------
REPORT:
i) At first I started the program with clear all, aclose all, clc, by using this commands we can clear all the screen in matlab.
ii) Second enter the inputs initial conditions and time points.
iii) Next reduce the second order ode into the first order ode, so that the pgm. will be a mnuch more easy.
iv) Plot the x &y, next inpu the vcalues after thatwrite the function for the second order ode.
v) Next creatte an animation.
vi) After that run the pgm.