I looked up similar questions but I still don't understand how to call values from string to propagate. When I try to run propagate I get an error that c isn't defined. I am assuming the same is true for delta t and x it's just that the error triggers on the first undefined variable it comes across.
def string(T, mu, length):
#legnth is just the number of elements in the array that represents the
#string, the strings length is 1m
delta_x = 1 / length
#c is the speed of the wave in the string
c = (T / mu) ** (0.5)
delta_t = delta_x / c
string_v = np.zeros((3,length))
return(string_v, delta_x, delta_t, c)
What do I have to do to allow the variables to be called in the next function?
def propagate(A, omega):
t = 0
r = c * delta_t / delta_x
string_v[0,0] = string_v[1,0] = A*np.sin(omega*t)
while t < 100:
for i in range(len(length)):
string_v[2,i] = 2 *(1 - r**2)*string_v[1,i] - string_v[0,i] + r**2(string_v[1,i+1] + string_v[1,i-1])
for i in range(len(length)):
string_v[1,i] = string_v[0,i]
string_v[2,i] = string_v[1,i]
t = t + delta_t
return(string_v)