Table of Contents
Modeling and simulating ensierin g syempe are essentiay tasks in g analying. Using Python misperlatearin s likee NumPy SciPy simpfies these by providing powernul for communicale and systems.
Settingg Up the Environment
Use pip commander to instalil NumPy and SciPy:
111; ASA1; FLT: 0 AF3; HUS3; pip instalis numpy scipy 1; FLT: 1 3; 13.3;
Modeling Engineering Systems
Insinyur syemos call often be represented using mathematical modes as diferenced as or transfer functions. NumPy provides for creatin matriticher and vectors, while Scple SciPy offs for solving equations and silations and sysistilations system responses.
Pemeriksaan singkat, sebuah estiple-spring-damper systemm can bune modeled with the diferensiasi equation:
m * x quapit; + c * x clumn; + k * x = 0
Systems Simulating
SciPy 's integrate module allawn solving diferensiasi equationals. The; solve _ ivp ghoun; function is commonlily upon for this. Here' s an example of simulating the -spine -damper systemm:
Define the syssim as a function:
111; WAL1; FLT: 0 AF3; Import numpy as np np 1; FLT: 1 13; 13;
1f 1; 1f; FLT: 0 13,3; fromm scipy.integrate import solve _ ivp 1f; FLT: 1 1f 3; 1f 3; 1f 3;
11; Syari1; FLT: 0 Aver3; def mass _ spring _ damper (t, y, c, k): 1; FLT: 1 1f 3; 1f; 1f 3; & lt; / i & gt;
return 1f; y 1f 1 = 1 = 3., - (c / m) * y 1; 1 = = -k / m;
Set initiaI conditions and paremeters:
11; Syaria1; FLT: 0 Aver3; initil _ conditions = Syari1; x0, v0 Aver3; 131; FLT: 1 123; 1f 3;
1f 1; 11; FLT: 0 123; t _ spar = 51; 0, 10 13.1; 131; FLT: 1 123; 123;
Call the solver:
1; FLT: 0 = 3; soluton = solve _ ivp (mass _ spring _ damper, t _ spon, initil _ conditions, args = (c, k))))) naf1; FLT: 1 1f 33; awhan3;;
Analyzing Resalts
After simulation, analze the results by plotting te sye systemm over time. Use pustakarees likee Matplotlib to visualize the data:
111; SUR1; FLT: 0 AF3; IPORT matplotlib.pyplot as plt 1; FLT: 1: 1 MBD; ASA3D;
11; Syarion1; FLT: 0; Abo3; plt.plot (solution.t, solution.y .0;; Aver3;;% 1; FLT: 1; 13; 1f 3;
11; Syari1; FLT: 0 Aver3; pl.xlabell (Engkau, Time (s) auson.1; FLT: 1: 1; Aver3;
11; Syaria1; FLT: 0 Aver3; plt.ylabell (Engkau, Diplacemt;) After 1; FLT: 1; Aver3;
11; FLT: 0 Abo3; pl.show () JUGA; FLT: 1 123; JUGA;