Project

pendulum motion by faical

to solve the second order diffirentielle equation the ODE45 solver was used as demonstrated in the attached code.

in order to make the animation the folowing steps was followed:

1- make a hanging point at coordinate (0,1) using the plot feature

2- draw a line corresponds to a radius of one which links the hanging point to the penduleum end

3- the coordinate of the pondelum as shown in the attached program was calculated as follow: x = sin(theata) and y= -cos(theta); where theta in radians

4-make a loop to plot all the points calculated for the given time 20s

5- make use of the pause feature to pause for 0.1 second before showing the next point, this trik will show the animation of the pendule

note: the animation will be shown once u execute the code so no need for me to recorde it and upload it via youtube

the code is inserted below

note : i used an embeded equations so i will post multiple files of code because i did not know how to upload and did not get answer when i posted in whatsup

first the embede functions to calculate the ODE

function xdot = ode_pend(t,x)
L=1;
m=1;
b=0.05;
g=9.81;
xdot(1) = x(2);
xdot(2) = -(b/m)*x(2)-(g/L)*sin(x(1));
xdot = xdot\';
end

second the code used to solve ODE and generate the animation

clc;
clear all;
close all;
% set the hanging point of the pondelum
x1=0;
y1=1;
% set the end point first location
x0=0;
y0=-1;
% solve the ODE
[t,x] = ode45(\'ode_pend\',[0 20],[0 3]);
% set values of theta as the first column of the ODE solution
x_radians = x(:,1);
% determin the number of pointed from the ODE solution
length_x = length(x_radians);
% loop through diffrent positions
for i = 1:length_x
    % calculate x coordinate from theta
    x0 = sin(x_radians(i));
    %calculte y coordinate from theta
    y0= -cos(x_radians(i));
    % plotting
    plot([x0 x1], [y0 y1],\'-ob\',\'MarkerSize\',5,\'MarkerFaceColor\',\'r\');
    % set the axis for proper animation
    axis([-2 2 -2 2])
    % pause will allow to see the slow motion of the animation it is a
    % trick used rather than saving images of the plot than prepare the
    % animation from the images
    pause(0.1)
    %hold off used to refresh the plot other ways the diffrent lines will
    %overlay each other
    hold off;
end

the below pictures show how it looks like the generated plots

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.