ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 14 Oct 2015 09:57:30 +0200'Integer' object is not callable error when it doesn't appear as though I'm calling an integerhttps://ask.sagemath.org/question/29983/integer-object-is-not-callable-error-when-it-doesnt-appear-as-though-im-calling-an-integer/ 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
%auto
#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))
else:
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 methodWed, 14 Oct 2015 03:49:11 +0200https://ask.sagemath.org/question/29983/integer-object-is-not-callable-error-when-it-doesnt-appear-as-though-im-calling-an-integer/Answer by vdelecroix for <p>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</p>
<pre><code>%auto
#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))
else:
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))
</code></pre>
<p>when I tested with</p>
<pre><code>tf(x) = x^2 - 2
newMet(tf, x, 1)
</code></pre>
<p>it gave me the error.</p>
<p>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</p>
<p>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</p>
https://ask.sagemath.org/question/29983/integer-object-is-not-callable-error-when-it-doesnt-appear-as-though-im-calling-an-integer/?answer=29984#post-id-29984Your 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.)
1.41421356237310
which looks like $\sqrt{2}$.Wed, 14 Oct 2015 04:12:18 +0200https://ask.sagemath.org/question/29983/integer-object-is-not-callable-error-when-it-doesnt-appear-as-though-im-calling-an-integer/?answer=29984#post-id-29984Comment by MFriend for <p>Your function has argument order func, deri, start, iters but you are calling it with start, func, deri, iters... By changing it I got</p>
<pre><code>sage: newMet(tf, x, 1.)
1.41421356237310
</code></pre>
<p>which looks like $\sqrt{2}$.</p>
https://ask.sagemath.org/question/29983/integer-object-is-not-callable-error-when-it-doesnt-appear-as-though-im-calling-an-integer/?comment=29991#post-id-29991ah that must have been the problem then, I restructured it and forgot to fix the restWed, 14 Oct 2015 09:57:30 +0200https://ask.sagemath.org/question/29983/integer-object-is-not-callable-error-when-it-doesnt-appear-as-though-im-calling-an-integer/?comment=29991#post-id-29991