Hello!
Problem: I can calculate xp(t) and xh(t) for any given t value, but not for ġ(t).
Context:
I'm calculating a general solution for a vibration system, using the Duhamel's integral. The result is a sum of 2 functions.
xg(t) = xp(t) + xh(t)
I'm also using Jet Brain's Datalore to quickly evaluate the results.
Lib:
import numpy as np
from numpy import pi, linspace
import sympy as smp
from sympy import sin, cos, tan, exp, symbols, Derivative, integrate, Integral, Function
from sympy.solvers.solveset import linsolve
import matplotlib.pyplot as plt
My constants:
k = 100*10**3 #[N/m] - Rigidity
m = 10000 #[Kg] - Mass
c = 20*10**3 #[N.s/m] - Damping
f0 = 5000 #[N] - Initial force
x0 = -0.05 #[m] - Initial position
v0 = 0.2 #[m/s] - Initial velocity
Main variables:
wn = float(np.sqrt(k/m)) #[rad/s]
zeta = float(c/(2*m*wn))
wd = wn*np.sqrt(1-zeta**2)
t0 = 2*pi/wn/2 #[s]
t1 = 5*2*pi/wn/2 #[s]
sloap = f0/t0
What I can do:
I can create a function xh(t), insert a t value and obtain a valid result (using my ti-nspire cx CAS to check):
A, phi = symbols('A phi', real=True)
t = symbols('t', real=True, positive=True)
def xh(t):
return A * exp(-zeta*wn*t)*sin(wd*t+phi)
I can do the same for xp(t):
x = symbols('x', real=True, positive=True)
xp_integral = (f0/t0) * x * exp(-zeta*wn*(t-x)) * sin(wd*(t-x))
def xp(t):
return 1/(m*wd) * integrate(xp_integral, (x, 0, t)).simplify()
And even for xg(t):
def xg(t):
return xh(t) + xp(t)
Where the trouble begins:
Now I need to solve a system of 2 equations, where I can get the values for A and phi.
xg(t=0) = x0 ← Normal function, for t=0 the result is the initial position [m].
ẋg(t=0) = v0 ← Derivative of xg(t), for t=0 the result is the initial velocity [m/s].
But I can't get the derivative of xg(t) to produce any value:
a, phi = symbols('a phi', real=True)
def d_xg(t):
return Derivative(xg(t),t, evaluate=True)
No mater the t value I throw in d_xg(t), it will always give me the same expression.
Any help is welcome, Thanks!
#Edit_01: changed def d_xg(t) to the current state.
When you call
d_xg(t)you are computing the symbolic derivative ofxgwith respect tot. If you calld_xg(t)multiple times you will always get the same expression because you are doing the same computation over and over again. Similarly, if you calld_xg(A), you will compute the derivative ofxgwith respect toA.Once you have computed
d_xg(t), you want to substitutet=0into that expression: