0

'float' object is not callable

This my code about plotting in python import pylab as py def h(t): return 1.2732*py.sin(2*t)+0.4244*py.sin(6*t)+0.25465*py.sin(10*t) +0.18189*py.sin(14*t)+0.14147*py.sin(18*t) def dh(t): return 2.5464*py.cos(2*t)+2.5464*py.cos(6*t)+2.5464*py.cos(10*t) +2.5464*py.cos(14*t)+2.5464*py.cos(18*t) def dh2(t): return(h(t+h)-h(t))/h pi=py.pi a,b,n=-pi,pi,10000 h=(b-a)/(n-1) ts=py.linspace(a,b,n) ys=h(ts) ys1=dh(ts) ys2=dh2(ts,h) py.figure(facecolor="w") py.plot(ts,ys,label="h(t)") py.plot(ts,ys1,label="exact h'(t)") py.plot(ts,ys2,label="computed h'(t)") pylab.xlabel('t') pylab.ylabel('S') pylab.grid() py.title("sawtooth function approximation and derivative") pylab.show() The result said: Traceback (most recent call last): File "", line 14, in TypeError: 'float' object is not callable Please help me, I need to summit my homework by tomorrow

15th Nov 2020, 5:21 PM
John
John - avatar
1 Antwort
+ 2
You have both a function h(t) and a global variable h with the same name. After the global variable is defined it overwrites the function and h(t+h) tries to cal the float variable h. You should rename one of them.
15th Nov 2020, 6:20 PM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar