I'm working on the code below for a class and no matter what I try I can't figure out how to fix it so I can move on.
def eqs(t, x):
return np.array([[(1 - np.multiply((1 - f(z(t), z_thresh)), (1 - f(x(1), y_thresh)))) - x(0)],
[(1 - np.multiply((1 - f(z(t), z_thresh)),(1 - f(x(0), x_thresh)))) - x(1)]])
f = lambda x, thresh: x >= thresh
z = lambda t: np.multiply((t >= 2), (t <= 4))
z_thresh = 0.5
y_thresh = 0.5
x_thresh = 0.5
x_0 = np.zeros([0,])
sol = int.solve_ivp(eqs, range(0, 6), x_0)
I've been banging my head against the wall all night and can't figure out how to get around. No matter what I seem to try it still throws "TypeError: 'numpy.ndarray' object is not callable."
Edit: The traceback is as follows:
Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_7252/1552450284.py in <module>
9 x0 = np.zeros([0,])
10
---> 11 sol = int.solve_ivp(eqns_a,range(0,6),x0)
12 plt.figure(1)
13 subplot(311)
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\ivp.py in solve_ivp(fun, t_span, y0, method, t_eval, dense_output, events, vectorized, args, **options)
540 method = METHODS[method]
541
--> 542 solver = method(fun, t0, y0, tf, vectorized=vectorized, **options)
543
544 if t_eval is None:
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\rk.py in __init__(self, fun, t0, y0, t_bound, max_step, rtol, atol, vectorized, first_step, **extraneous)
92 self.max_step = validate_max_step(max_step)
93 self.rtol, self.atol = validate_tol(rtol, atol, self.n)
---> 94 self.f = self.fun(self.t, self.y)
95 if first_step is None:
96 self.h_abs = select_initial_step(
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\base.py in fun(t, y)
136 def fun(t, y):
137 self.nfev = 1
--> 138 return self.fun_single(t, y)
139
140 self.fun = fun
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\base.py in fun_wrapped(t, y)
18
19 def fun_wrapped(t, y):
---> 20 return np.asarray(fun(t, y), dtype=dtype)
21
22 return fun_wrapped, y0
~\AppData\Local\Temp/ipykernel_7252/1552450284.py in <lambda>(t, x)
6 x_thresh = 0.5
7
----> 8 eqns_a = lambda t, x: np.array([[(1 - np.multiply((1 - f(z(t), z_thresh)), (1 - f(x(1), y_thresh)))) - x(0)], [(1 - np.multiply((1 - f(z(t), z_thresh)),(1 - f(x(0), x_thresh)))) - x(1)]])
9 x0 = np.zeros([0,])
10
TypeError: 'numpy.ndarray' object is not callable
CodePudding user response:
the traceback tells you that the problem is in
np.array([[(1 - np.multiply((1 - f(z(t), z_thresh)), (1 - f(x(1), y_thresh)))) - x(0)], [(1 - np.multiply((1 - f(z(t), z_thresh)),(1 - f(x(0), x_thresh)))) - x(1)]]
So we look for apparent function calls, fn(...)
. np.multiply
should be ok unless you redefined it somplace. f(...)
is defined with a lambda
. z(...)
as well. That leaves x(1)
and x(0)
. What is x
? It's the lambda function argument.