0
x = Symbol ("x")

f = log(x)
dif1 = diff(f,x)
dif2 = diff(dif1,x)
dif3 = diff(dif2,x)
dif4 = diff(dif3,x)
dif5 = diff(dif4,x)

def D11(a,h):
    return (f.evalf(subs={x:a+h})-f.evalf(subs={x:a}))/h + (h/2)*dif2.evalf(subs={x:a+h/2})

def D12(a,h):
    return ((f.evalf(subs={x:(a+h)}) - f(a-h)))/(2*h) - h**2/6*dif3.evalf(subs={x:(a)})

def D13(a,h):
    return (f.evalf(subs={x:(a-2*h)})- 8*f.evalf(subs={x:(a-h)}) + 8*f.evalf(a+h) - f(a+2*h))/(12*h) - h**4/30*ftuletis5(a)

def D22(a,h):
    return (f.evalf(subs={x:(a+h)}) - 2*f.evalf(subs={x:(a)}) + f.evalf(subs={x:(a-h)}))/h**2 - h**2/12*(dif4.evalf(subs={x:(a)}))

vigaD11 = []
vigaD12 = []
vigaD13 = []
vigaD22 = []
h=[]

for i in range(20):
    h+=h+[(10**(-i))]
    vigaD11+= vigaD11 +  [(D11(2,h[i])-(dif1.evalf(subs={x:2})))]
    vigaD12+= vigaD12+[(D12(2,h[i])-(dif1.evalf(subs={x:2})))]
    vigaD13+= vigaD13 + [(D13(2,h[i])-(dif1.evalf(subs={x:2})))]
    vigaD22+= vigaD22 [(D22(2,h[i])-(dif2.evalf(subs={x:2})))]

I get an error message saying that log object is not callable. Currently I'm using the math package and Sympy package to get the program to do what I want.

The error message I get:

Traceback (most recent call last):
  File "C:\Users\arman\Desktop\Numbrilised meetodid\praktikum12\praktikum12.py", line 64, in <module>
    vigaD12+= vigaD12+[(D12(2,h[i])-(dif1.evalf(subs={x:2})))]
  File "C:\Users\arman\Desktop\Numbrilised meetodid\praktikum12\praktikum12.py", line 37, in D12
    return ((f.evalf(subs={x:(a+h)}) - f(a-h)))/(2*h) - h**2/6*dif3.evalf(subs={x:(a)})
TypeError: 'log' object is not callable

It still does not work when I specifically call out the sympy version of log. Please help.

2 Answers2

0

You could try f = math.log(x) or whichever log function you want to use. Maybe python just doesn't find the right function to call.

sfphoton
  • 127
  • 1
  • 7
0

In an isympy session with * import ofsympyandxsymbol,log` a sympy object

In [1]: log                                                                     
Out[1]: log

In [2]: x                                                                       
Out[2]: x

In [3]: f = log(x)                                                              

In [4]: f(23)                                                                   
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-a73e6f7d2549> in <module>
----> 1 f(23)

TypeError: 'log' object is not callable

You can't call log again; it's already been "called". You can evaluate it at specific number with:

In [13]: f.evalf(subs={x:1.23})                                                 
Out[13]: 0.207014169384326

You do that once in the problem expression, but not the second time. Why not?

f.evalf(subs={x:(a+h)}) - f(a-h)
hpaulj
  • 221,503
  • 14
  • 230
  • 353