Challenge

Week 3 - Solving second order ODEs

clear all
close all
clc


b=0.05;
m=1;
l=1;
g=9.81;


%initial condition

theta_0=[0;3];

%time points

t_span=linspace(0,20,200);

%solve ode

[t,results]= ode45(@(t,theta) ode_func(t,theta,b,g,m,l),t_span,theta_0);

plot(t,results(:,1));
hold on

plot(t,results(:,2));

ylabel('plot');
xlabel('time');

%pendulum
figure(2)
for i = 1:length(t_span);

x0=0;
y0=0;

x1= 1*sin(results(i,1));
y1=-1*cos(results(i,1));
plot ([x0 x1],[y0 y1],'linewidth',3);
hold on
plot ([-0.5 0.5], [0 0],'linewidth',3);

%plotting pendulum bob;
plot (x0,y0,'o','markersize',10,'markerfacecolor','b');

%joining end points of line and fixed end
plot (x1,y1,'o','markersize',6,'markerfacecolor','k');

%connecting bob and fixed end
plot([x0 x1],[y0 y1],'linewidth',2);
axis ([-1.5 1.5 -1.5 1.5]);

M(i)=getframe(gcf);
% ct=ct+1;
hold off

end

movie(M)
videofile=videoWriter('ODE.AVI','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile);

HERE THE EXPLANATON OF CODE;

THE GIVEN EQUATION IS

d^2/dt^2+b/m dtheta/dt+g/LSINTHETA=0

the given values are:

b=0.05(damping coefficent);

m=1(mass);

g=9.82ms/s^2 (damping coefficent)

there are two order odes

velocity and dispalcement

velocity=3

dispalacement=0

initial condition for displacement

theta_o=0.5

initial pendulum=0

initial velocity=5m/sec

there the time points

t_span

the span is for calculating the time points

in the time span we using the linespace command for calculting the pendulum counting here we use the 0 to 20 for 200 times

we have to solve the function

ode 45 its the referens take by the refernce rk theory partial differntial equation using a numerical method..

function of [d theta_dt]=ode func(t,theta,b,g,l,m);

explanation this function

dtheta1_dt = dtheta a2

dtheta2dt=-b/m*theta 2 -g/lsin theta

plot will be using the make a graph

t_results _:1

plot results (t,theta:2)

x label is use for plot and y label for time

for pendulum

for using the for loop to make a pendulum of degress sin and cos degress

plot for the pendulum bob and joining end for line and fixed end points

for frame function get frame will be used gcf

movie m file reader to make a pendulum movie an video writer

close window for finish the video file

ERROR FACING:

1

ERROR 1 WHILE I FACED:

line 22 i missed the brackets by multiplication for construct the matrix using the brackets

to rectify the error

and am put the brackets and mention the brackets for theta and its should be solved

error 2

error i faced

inavlid expression missing the extra character y=o

error to be rectified

put the y o for putting y zero and its be solved;

ERROR 3

ERROR I FACED

FOR PLOTING am not putting brackets to xo x1 yo y1

error i rectified

am putting the individual square brackets for [xo x1[ yo y1] for this...

ERROR 4

error i faced in line 55 am putting m(mct)=getframe ct will be mention on this one

error am rectified

i mention the ct =%comments for invalid the function of (ct) and its should be cleared:

output;

ANIMATION OF PENDULUM

YOUTUBE LINK

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.