lundi 15 novembre 2021

How do I store "z" as a variable that contains more than a single value?

How do I store z as a variable with more than a single value instead of the code rewriting z after each loop?

import numpy as np

def equation1(m,k,x,deltat):

    Fpeak = 1000 + 9 * x**2 - 183 * x
    td = 20 - 0.12 * x**2 + 4.2 * x

    w = np.sqrt(k/m)
    T = 2 * np.pi / w
    time = np.arange(0,2*T,deltat)

z=[]
for t in time:
    if (t <= td):
        z = (Fpeak/k) * (1 - np.cos(w*t)) + (Fpeak/k*td) * ((np.sin(w*t)/w) - t)
    else:
        z = (Fpeak/(k*w*td)) * (np.sin(w*t) - np.sin(w*(t-td))) - ((Fpeak/k) * np.cos(w*t))
    
    return(z)

print(equation1(200,1000,0,0.001))

Aucun commentaire:

Enregistrer un commentaire