Project

Week 3 - Solving second order ODEs

The Differential equation has many applications in various engineering applications and science. It is very important for engineers to be able to generate physical problems using mathematical calculations and then solve these calculations to further the behavior of the systems involved.

How the pendulum moves depends on Newton\'s\' second law. When this rule is written, we find the second-order Ordinary difference Equation that describes the position of the \"ball\" in relation to time.

GOVERNING EQUATIONS & GRAPHS


In the above equation

g = gravity in m/s2

L = length of the pendulum in m

m = mass of the ball in kg

b=damping coefficient

MAin code:-

clear all
close all
clc

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

theta_0 = [0;3];

t_span = linspace(0,20,200);

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

figure(1)

plot(t,results(:,1));
hold on
plot(t,results(:,2));
title(\'Damped Harmonic motion of a Simple Pandulum\');
legend(\'Angular Displacement\',\'Angular Velocity\');
xlabel(\'Time (Sec)\');
ylabel(\'Plot\');
grid on;
hold off

ct=1;
for i= 1:length(results(:,1))
    x0=0;
    y0=0;
    x1=l*sin(results(i,1));
    y1=-l*cos(results(i,1));
    
    figure(2)
    plot([-0.5,0.5],[0,0],\'linewidth\',8,\'color\',\'blue\');
    hold on;
    line([x0 x1],[y0 y1],\'linewidth\',1,\'color\',\'green\');
    plot(x1,y1,\'o\',\'markers\',15,\'markerfacecolor\',\'red\');
    grid on;
    title(\'Animation behaviour of a Simple Pandulum\')
    legend(\'Support Base\',\'Length = 1m\',\'Ball Mass = 1Kg\');
    axis([-2.5 2.5 -3 0.5]);
    pause(0.03);
    hold off;
    M(ct) = getframe(gcf);
    ct=ct+1;
end

movie(M)
videofile = VideoWriter(\'Damped_pendulum_animation.avi\',\'Uncompressed AVI\');
open(videofile)

writeVideo(videofile,M)
close(videofile)

Function :-

function[dtheta_dt] = ode_func(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

Code Explanation :-

First, we plot the behavior of the pendulum for a moment rather than create images of a simple pendulum movement.

Step description of the pendulum behavior graph correction code:

First, we must provide the necessary input that measures (b), pendulum height (L), ball weight (m), and vitality (g).

We should give the theta value in the matrix form because it contains 2 values namely angular velocity and angular velocity.

We have to allocate the estimated time and convert this space into an equivalent space with the use of the linspace command.

We should use the ode45 command to solve the first ODE with the help of the sub-function (ode_func) by assigning the angular and angular velocity distribution at any time.

In the implementation, we solve our 2 equation by adding a given.

Now the plot is a graph of the angular displacement of the ball in relation to time and angular velocity in relation to time.


Solve Second Order ODE of Sale Pendulum

and Animation also motion Projects - Skil-Lync

We plot these two graphs numerically so we use the myth command to easily understand the angular displacement and the angular velocity curve. Using the order title gives the graph title

The first of the pendulum\'s display distances in a different number. we set the sum.

We apply a loop to the change of display with displacement in relation to time.

Respond to a string connection at the end of a constant (x 0.y0 = (0,0)

We need to calculate the free end-of-wire coordinates (X 1 y 1 ) according to the number of time-dependent angles.

We have to set the pivot line the thread is on.

After that, we have to arrange another line to show the ball balance.

Now edit the graph string.

We have to point the ball to the animation so we use the marker to edit the theme.

We must give the correct value for the X and Y-axis.

To keep the rest in the ball we use the stop order.

We have to create a new M variable to keep the current mathematical frame.

We must provide an addendum to resist the command.

Then after the loop, we have to make a conversion movie that is used to save the frame. Therefore, the final images are constructed.

ERROR:

Many errors occur due to typing mistakes, I manage to remove all those by reviewing the code multiple times.

RESULT:

Animation Link :- https://youtu.be/wHyPY-Dc8SY

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.