Challenge

Week 3 - Solving second order ODEs

AIM - TO SIMULATE THE TRANSIENT BEHAVIOUR OF A SIMPLE PENDULUM BY USING MATLAB
% Programe for trnsient behavior of a simple pendulum by using second
% oreder ODE equation
d^2(theta)/dt^2 + b/m(d_theta/dt)+g/l* sin(theta)=0
close all
clear all
clc
% INPUTS
l=1; [ % length of the pendulum m]
m=1; [% mass of the ball kg]
b=0.05; [ % damping coefficent]
g=9.81; [ % accelration due to gravity]
ct=1;
% Initial conditions
theta_x = [0;3];[ % angular displacement]
t_span = linspace(0,20,300); [% time span]
% solution [ Byusing ODE45 FUNCTION]
[t,results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_x);
% plot 1
figure(1)
plot(t,results(:,1),'LineWidth',3)
hold on
plot(t,results(:,2),"LineWidth",3)
xlabel('angular displacement (rad) / angular velocity(rad/sec)')
ylabel ('time (sec)')
title (' transient behaviour of a simple pendulum')
legend('angular displacement,angular velocity')
grid on
for i= 1:length(t_span)
j= results(i,1);
x0 = 0;
y0 = 0;
x1 = l*sin(j);
y1 = -l*cos(j);
% plot 2
figure(2)
plot([-1 1],[0 0],'Linewidth',4,'color','g')
hold on
plot([x0 x1],[y0 y1],'LineWidth',3,'Color','b')
plot([0 0],[0 -1],'LineWidth',2,'Color','r')
plot(x1,y1,'Marker','o','MarkerSize',15,'MarkerFaceColor','r')
xlabel('X-axis (m)')
ylabel('Y-axis (m)')
grid on
axis ([-2 2 -1.5 0.5])
pause(0.03)
ct=ct+1;
M(ct)= getframe(gcf);
end
movie(M);
videofile = VideoWriter('Simple Pendulum Motion.avi','Uncompressed AVI');
open(videeofile);
writeVideo(videofile,M);
close(videofile);
Then the Animation of simple pendulum link is below
The line daigram for the SIMPLE PENDULUM are
The Angular VELOCITY and Angular DISPLACEMENT are
In the running the code i am facing several errors , the errors are shown by the command window ,
then the errors are
these error is i am gives the incorrect mismatched variables , untill solve the error is correctly and next i am facing another error are
i am facing the above errors while write the programming and what i am doing my mistake and clearly by find out by using command window ,
THE WORK SPACE IS
CONCULTION
1- IN the make code for running pendulum by the use of ode eqation [ d^2(theta)/dt^2 + b/m*d(theta)/dt +g/lsin(theta) =0
2- these the equation which is used to find the ODE
[t,results]= ODE45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0)
the above equations which are used to make the plots .
The ANIMATION OF SIMPLE PENDULUM LINK AS GIVEN BELOW
%[https://drive.google.com/file/d/1KWPzC6w5eQN7zdMAJfto9UgvRu89zj3f/view?usp=sharing]
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.