butiran

fd damped oscillation dt

description

formulation

initial conditions

parameters

code

import math

T = 1
tbeg = 0
tend = 4 * T
N = 1
dt = (tend - tbeg) / N
time = [(i*dt + tbeg) for i in range(N+1)]

k = 4 * math.pi**2
m = ( T**2 / (4 * math.pi**2) ) * k
omega = 2 * math.pi / T
gamma = 0

x0 = 1
v0 = 0

tt = []
xx = []

for t in time:
  if t == tbeg:
    v = v0
    x = x0
    a = - 2  * gamma * v - omega**2 * x
  else:
    a = - 2  * gamma * v - omega**2 * x
    v = v + a * dt
    x = x + v * dt
  
  tstr = f'{t:.3f}'
  astr = f'{a:.3f}'
  vstr = f'{v:.3f}'
  xstr = f'{x:.3f}'
  
  print("{x:", tstr, ", y:", xstr, "},", sep="")
  
  tt.append(float(tstr))
  xx.append(float(xstr))

print()
print(tt)
print(xx)

It is available at https://onecompiler.com/python/3znm4u5zv .

solution 1

solution 2

solution 3

solution 4

solution 5

summaries