Ask Your Question

'Integer' object is not callable error when it doesn't appear as though I'm calling an integer

asked 2015-10-13 20:49:11 -0500

MFriend gravatar image

I have a cell where I'm trying to make a recursive function to shortcut Newton's Method, and it appears to be written properly, but I keep getting the error shown above

#don't call this, it's an internal function that the main one calls for its recursion step
def newtonsMethodRecursiveCall(func, deri, start, iters):
    if iters == 0:
        return start - (func(start) / deri(start))
        r = newtonsMethodRecursiveCall(start, func, deri, iters-1)
        return r - (func(r) / deri(r))

# Recursive function to perform Newton's Method to the nth degree
def newMet(func, vari, start, iters = 10):
    deri(vari) = derivative(func, vari, 1)
    return (newtonsMethodRecursiveCall(func, deri, start, iters))

when I tested with

tf(x) = x^2 - 2
newMet(tf, x, 1)

it gave me the error.

I don't see anywhere that should indicate that I would be calling an integer, I thought I'd checked all of the names to make sure they were undefined before attempting to call them as a function

as a side note, I don't care if there's already a function for what I'm doing, I wanted to try to write one myself using the definition of newton's method

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-10-13 21:12:18 -0500

updated 2015-10-13 21:12:37 -0500

Your function has argument order func, deri, start, iters but you are calling it with start, func, deri, iters... By changing it I got

sage: newMet(tf, x, 1.)

which looks like $\sqrt{2}$.

edit flag offensive delete link more


ah that must have been the problem then, I restructured it and forgot to fix the rest

MFriend gravatar imageMFriend ( 2015-10-14 02:57:30 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-10-13 20:49:11 -0500

Seen: 582 times

Last updated: Oct 13 '15