Week 4.1 - Solving second order ODEs
Aim:
1. Create code for the equation.
2. Create plot according to the equation.
3. a.Create vedio file and Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.
Your animation does not have to look exactly like this and here is the logic.
b. For each value in time
c. Create an image that represents the position of the pendulum
d. You can assume the length of the string and the size of the ball
e. Use the marker command to create a sphere
f. One end of the pendulum is fixed
g. The other end moves according to the solution of the ODE you had solved.
h. If you are using using Matlab, use the movie command create an animation
4. Submit a report that has the following content:
i. Step wise explanation of your code.
ii. Errors faced while programming.
ii. How have you overcome those errors.
Screenshots showing errors thrown in command window.
Objective :
1. write a codescript and function file to run this ODE function.
2. Create plot as per the output of the solution.
3. Create movie or animation of the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.
4. Upload the vedio on youtube and Drop the youtube link.
Governing Equation:


Body of the project:
Function file :
Explaination:
Clear all is used to clear previous variables, values, size arrays from the workspace
Close all is used to close all the previous program.
Clc is used to clear all the values from the command window.
Initial condition is Adding the inputs , variables in the input- b,g,m & l.
where, b is the damping co-efficient,
g is the gravitationalforce,
m is the mass of the ball,
l is the length of the string.
for getting the plot 'ANGULAR VELOCITY' VS 'TIME' graph - need points which makes the curve.
there is two first order ODE. One is for velocity and another one is for displacement.
so, getting the initial condition we need the value of theta which is actually nothing but the displacement;
Explaination:
Here the second order ODE has been converted into first order ODE by representing theta as theta1 and (dθ/dt) as theta2 then (d^2θ/dt) will become (dθ1/dt).
theta1 is the angular velocity and theta2 is angular displacement respectively.
Here, we have represented the two ODE as,
dtheta1_dt = theta2
dtheta2_dt = -(b/m)*theta2 - (g/l)*sin(theta1) and then solution vector is created dtheta_dt.
Then the function is imported to the main matlab program.
For Creating The Animation file:
amplitude = results(:,1)
The reason I am taking the amplitude so that i can save the each and every matrix of resulsts(:,1) in the workspace.
next, apply for loop to get the iteration,
for getting the gridline in the animation 'grid on' command is used
here, i am taking the variable 'M' as an array and for getting the iteration of 500 times .
i want an increment of 'ct' as each and everytime after forloop get executes. thats why i am writing the counter value as
'ct =ct+1'
after that i am ending the for loops so that code get executed and complete the iteration as per the equation inside the for loop and get
different positioned plot which is used to make the video.
For getting the visualise the animation for particular time the command will be written as
pause(' write required time')
i.e ,
pause(0.05)
For making movie I am using movie(M) command.
for naming the Videofile = VideoWriter('forward_kinematics.avi'); command is used
for opening the video file open(videofile) command is used.
to write the video 'writeVideo(Videofile,M)' command is used.
for closing the videofile 'close(Videofile)' command is used.
after running the whole code, Matlab succesfully created a vedio by using the plot.
Note: I am attaching the youtube link -https://youtu.be/jjzHdQ9eK_M
Conclusion:
From that challenge we can understand how to apply the concept of ODE in Matlab and plot the graph of 'ANGULAR VELOCITY' VS 'TIME'.
We learned to apply the code to create plot of different positions of the pendulam and by the help of these plots we can make a vediofile by the name of 'SIMPLE PENDULAM'.
ERROR FACED AND RECOVERY:
Error and Reason :
The reason for the error is mostly spelling mistakes, missing of parenthese , wrong execution of the command i.e while giving the input of the command bracket() or coma , missing.
Most Fatal Error was graph is not plot properly i.e somtimes horrizontal line and String is not showing, But bob is showing in the graph , also Simple Harmonic Motion of PENDULUM was not showing.
While making the animation file, animation could not be created due to the mistakes in command or spelling mistake of the command.
Recovery:
1.By debugging the code step by step those missing parenthese, brackets and the checking the spelling mistakes of the commands ractified and solved.
2.By discussing with the technical support team and implementing the suggestions in the code the animation and plot created successfully.
3. Checking the command sequence and correcting the commands and inputs the code is recovered successfully
Note: This code runs successfully after 8 times of execution.