You are on page 1of 8
Simulation of a Simple Pendulum on Python @ Yue Comments (0) Upvote (0) "@ Downvote (0) Mathematical model 5 2 0+ (3) 4+ (2) -sin(a) =o where, 8 = Angular Acceleration’ 0 = Angular Velocity @-Angular Dsplacernent b= Damping Factor = Acceleration due to gravity = 9.81 (mis"2)° L = Length of pendulum” 1m = Mass of bob* Converting this second order differential equation to two first order diffential equations:~ Let, 0, = 0 and 6; = 6 = 8 > =0=6, Thus, the lst order dffrental equations are, ie (-B) oe (-$) at = 6 Cader Simulation of Sinple pendulum # Importing Libraries import math mport numpy as np fron seipy.integrate Inport solve_Svp import matplotLib.pyplot as plt mport os f initial and end values st=o 4 start tine (5) et = 20.4 # End tine (5) t= 0.3 ft Tine step (5) = 9.8 # Acceleration due to gravity (#/s*2) tea 4 Length of pendulue (m) b=as 41 damping Factor (ka/s) ped 4 Mass of bob (ke) 4 Ast order equations to solve in a function ‘thetal 1s angular displaceent at current tine instant ‘theta2 1s angular velocity at current tine instant thetaz_dt is angular acceleration at current tine instant thetat_dt is rate of change of angular displacenent at current tine instant {.e. same as theta2 def sim_pen_ea(t theta) ddthetaz_dt = (-b/m)*theta[] + (-g/L)*np-sin(thetale]) ddehetat_ot = theta(3] return [athetat_dt, dtheta2_at) main thetai_ini = @ 4 Initial angular displacenent (raé) thetaa_int = 3 4 Initial angular velocity (rad/s) theta_ini = [thetat_ini, thete?_sns] ‘span = [stjetsts] t= nprarange(st,etets.ts) sim_points = Len¢t) 1 = np.arange(@, sin points,1) thetai2 = solve_ivp(sin_peneg, t_span, theta_ini, teval = t) thetaa = theta12.y[8,:] theta? « thetar2.y[2,2] plt.plot(t,thetat,1abel=" Angular Displacement (rad)') plt.plet(t,theta2, abele" angular velocity (rad/s)") plt.xdabel(Tine(s)") plt.ylabel( ‘Angular Disp. (rad) and Angular Vel.(rad/s)') plt-legend() plt.show() f Simulation Leap. sin(thetan) -Lenp.coscrnetaz) for point in a: os.system("Ffnpeg -F image? -r 28 -4 smagexesd.png -veodec mpegs -y novie.avi") Alter solving the diffrential equation, the code will generate multiple frames of position of pendulum corresponding to each time instant in the array Each ofthese frames or figures willbe saved with the name format as imageOO000 png"image000O1 png"imageOOOO2Z,png’ and so on. Then, the code wil al the os and pass a comand line to the 0s to stich the images together to make a movie, Note that the definition of this comand line is in ffmpeg library. The figures plt.Figure() pit. plot(x{point],y{point), "bo" ,markersize=20) plt.plot({2,x{point]}, (0,yLpoint]]) pit xlie(-L-@.5,149.5) pit.ylin(-1-0.5, 140.5) plt.xlabel(‘x-direction") pit. ylabel(‘y-direction' ) FLlenunber = point ‘#Llenunber=foreat(#ilenurber,"@5") +#LLenane="inage()}-png”format(#ilenutber) plt. savefig( Filename) plt.close() and the movie willbe saved inthe same directory where the code file is saved. Link to download ffmpeg: httpsu/fimeeg zerance.cor/oullds/ Blot ular Vel(rads) “Angular Disp.lrad) and A Angular Displacement (rad) — Angutar velocity (aes) Time(s} Simulation ‘Simulation of a Simple Pendulum on Python LEAVE A COMMENT ‘Thanks for choosing to leave a comment. Please keep in mind that ll comments are moderated according to our comment policy, and your email address wll NOT be published, Let’s have a personal and meaningful conversation, No comments found More projects by Yug a ‘Optimal control and estimation of 2D non-linear quad-copter mode! ag updates on Mar 27,2019, 0400am ST hitps//drive.google.comMtrive/folders/IOZEzkHeXUtméqiadZIdtrXONFTPZVOAA?usp=sharing Read more ‘Numerical solution to Bose-Einstein Condensation in 3D ag updates on in 1,201, 09:06pm IST Drive link- https:/fdrive google-comidrive/folders/ibb-~7hu)8B9NM2e_LirqTcAL7GHmmLS7?uspesharing Read more ‘Breaking Ice with Air cushion Vehicle - Find minimum pressure with Newton-Raphson method Yaeupated on Aug 7, 2018, 08526 1ST Equaion for ke Breaking wth an Ar Cushion Veh oh ia oo ht\' Pp) + (04 neo) Sp (EE) <0 p+ presure h 1 = sizeof the ae cushion “betae"Function of width thickness of the ice ¢ = tensile strength of the of the ice. Read more Engine Data Analysis on Python This code takes takes the data from a user specified CONVERGE format file It also checks the file for the correct format ie. compatibility. the files not a CONVERGE output data format then the code will throw an error statement “This is nota valid CONVERGE output file” Also ifthe file format is correct but... Read more, ‘Simulation of a Simple Pendulum Ya update on 25,2018, 09 nist b= 0.5 Damping factor (kg/s) m= 1 Mass (kg) g= 9.81 Acceleration due to gravity (rvs“Z) L=1 Length of Pendulum (rm) Angular displacement (rad) Angular velocity (rad/sec) simple_pendulum_sun 9% This script simulates simple pendulurn motion % Clearing close all clea; cle; % Inputs b = 0.5; % Damping...ead mare ‘Curve fitting over Specific heat vs Temperature data on Python Yap paateson i 8, 2018, 0708pmI5T This project is on cure fitting given a data set containing range values for two variables, temperature and specific heat in this case. This code uses curve_fit function from scipy to fit inear,qudratc.cubic and multiple functions to the data set. Finally, it algo caleulates mean squared error for each fit." This. Read more Curve fitting specific heat and temperature data This code fits the specific heat vs temperature data to linear and cubic curve and plots orginal data, linear fit and cubic fit, It also displays mean squared error for both linear fit and cubic fit % Curve fitting Specific heat vs temperature %Clearing close all clear; cl: data = load(data); temp = data, 1) cp...Read more MATLAB code to plot P-V diagram of Otto cycle and calculate it's thermal efficiency, Otte cycle processes Process 1-2 (Isentropic compression) Process 2-3 (Contant volume heat addition) Process 3-4 (Ientropic expansion) Process 4-1 (Contant volume heat rejection) ‘main_script’ has all the inputs and calculates state variables ie pressure, volume and temeprature. Then, it calls ‘v_at_crank_anglem:. Read more Python code to plot P-V diagram of Otto cycle and calculate it's thermal efficiency, ag upated on 18,2018, 0409p IST Cte cycle processes Process 1-2 (Isentrople compression) Process 2-3 (Contant volume heat addition) Process 3-4 (Isentropic expansion) Process 4-1 (Contant volume heat rejection) Themal efficiency, Drag force calculations and plots ag upates on 1, 201803 pm ist Fe (Cd * A * tho * v"2/where, Cd = Dragcoef ficientA = Areatho = Densityof fluidy = velocityF_d'= Drag force Part 1: Ploting Drag force vs velocity (drag_force). This script plots Drag, force vs velocity, % Plating Drag force vs velocity 9 CLearing.. Read more Ca Arpt — Part! Ploting Drag force vs velocity. Ths script plots Drag force vs velocity. ry here, Ca Drag coefficient A = Area pe = Density of fluid v= velocity Fy Drag force Code to calculate drag force experienced by... Read more 2R Roboti m Simulation on MATLAB ag upates on on 26,2018, OF0Tpm IST This MATLAB code simulates a 2 link robot Kinematics for each link moving from O degree to 90 degrees. ‘two_R_Robotic_Arm_Simulation.m %% Clearing close al; clear; le; 9% Inputs t= 1; % Length of Link 1 (n) (2= 05; % Length of Link 2 (m) theta = 0:10:90; % Range of values of angle for Link t and 2 wrt X-direction. Read more ‘28 Robotic Arm Simulator on Python Ya updates on jun 19,2018, 0327p IST This code simulates a 2 lnk robot with each link travelling from O degree to 90 degrees. # 2R Robotic Arr ‘Simulator import matplotlib.pyplot as plt import numpy as np import math import os # Inputs start_angle © end_angle = math pil2 x0 = 0 # x-co-ordinate of Link I, base connector yO = 0 # y-co-ordinate of. Read more Parsing NASA thermodynamic data on MATLAB Yaa updates on an 12,2018, 06:23pm IST ‘This code asks for substance molecular formula as input. It outputs the molecular weight It takes the co- cffcient data of the corresponding substance from NASA thermodynamic datafile narned ‘therm dat’. Then, itcalculates the specific enthalpy, specifi entropy, and specific heat for range of temperature...Read more ‘Maximization of Stalagmite Function using Genetic algorithm on MATLAB Mag upateson jan 2018, 0454 ST 1. Genetic algorithm is an optimization method that mimics natural process of evolution. A population of input parameters (chromosomes) is generated randomly. Then, the fitness of each parameters calculated by applying the parameters to the Ftness function to be optimized, Next step is the selection process. In this. Read more “Top Indvidal Courses Top Master Courses OurCompany SKILL©LYNC Ppthanand conten ges srnganeMauetsceiion Beli 194 ad Poo ami Nag ausvsiotbent Deen non Masters ecteton es Pagan OurBlogs pec ere AfaCAD 16x 7-Dinndn Sand Os, | ADD Hag eran Peale | Peel don 4iPut 3 Outing Ds Surin anders | Hgh-otentl Cres in the Furl Cains | Sactrsand ass ha Aft Smalaton in oduct Deweney | awa en sn relent ts | 2 ett AUGCAD 247 Mow aCiceuans |Tefie ‘dgCAD2 ut enadOimencon Ses | Gere YouNeeétokoow Ast ETARS | Te fata Md Decent cin Gree ctomseeangDi | The asco ald Desgn? ar. ACkas Lenka Detoamert an Mautchig | Th Bao Male Pu esgic Ming ssesSaceConl=fae? | Tei arene of MsoCAD Ua TA aon ne [econ Sues Cnl ns | etude Png ctr fesus | Te iof MlOnp at ILA Lack Pung Se nts 600 (0

You might also like