# TypeError: 'sage.rings.integer.Integer' object is not callable

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi there.

I am new to SAGE and I am getting this error when doing an integration. I am not sure if I am doing correctly the power 2 of the sech function.

I defined f function and my code is:

var('c,H,k,d,x,t')

f=(c * H * (sech^2(k / d * (x - c * t))))/(d + H * (sech^2(k / d*(x - c * t))))

f.integral(t)


The error is:

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "_sage_input_7.py", line 10, in <module>

exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + support_.preparse_worksheet_cell(base64.b64decode("dmFyKCdjLEgsayxkLHgsdCcpCmY9KGMgKiBIICogKHNlY2heMihrIC8gZCAqICh4IC0gYyAqIHQpKSkpLyhkICsgSCAqIChzZWNoXjIoayAvIGQqKHggLSBjICogdCkpKSkKZi5pbnRlZ3JhbCh0KQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))

File "", line 1, in <module>

File "/tmp/tmpGxgMcP/___code___.py", line 4, in <module>

f=(c * H * (sech**_sage_const_2 (k / d * (x - c * t))))/(d + H * (sech**_sage_const_2 (k / d*(x - c * t))))

TypeError: 'sage.rings.integer.Integer' object is not callable


Any corrections and/or suggestions will be welcome. Thanks in advance.

P.S. - Hope the edit improved the reading of the topic, but could not find how to display colors as you did in TypeError, etc.

UPDATE:

So after correcting the sech above to sech(x)^2, I calculate the integral of f between the limits 0 and t, and changed the second line of the code above to:

limit(f=(c * H * (sech(k / d * (x - c * t))^2))/(d + H * (sech(k / d*(x - c * t))^2)),t=t)


Now I get the following errors:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_18.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dmFyKCdjLEgsayxkLHgsdCcpCmxpbWl0KGY9KGMgKiBIICogKHNlY2goayAvIGQgKiAoeCAtIGMgKiB0KSleMikpLyhkICsgSCAqIChzZWNoKGsgLyBkKih4IC0gYyAqIHQpKV4yKSksdD10KQpmLmludGVncmFsKHQp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>

File "/tmp/tmpJsB9eB/___code___.py", line 4, in <module>
limit(f=(c * H * (sech(k / d * (x - c * t))**_sage_const_2 ))/(d + H * (sech(k / d*(x - c * t))**_sage_const_2 )),t=t)
TypeError: limit() takes at least 1 argument (0 given)


Any idea what is wrong here?

The syntax of limit seems correct but how to specify both limits of 0 and t for the integral?

edit retag close merge delete

Sort by » oldest newest most voted

Expressions such as $\cos^2 x$, $\sin^2 x$ are shorthand mathematical notation for $(\cos(x))^2$, $(\sin(x))^2$.

In Sage, you have to input them as cos(x)^2, sin(x)^2, as Sage does not parse the above shorthand notation.

The error message you are getting is because Sage thinks you want sech to the power 2(k / d ...) and it is telling you that the integer 2 is not "callable", as a function would be (eg if f is a function, you can call f(k / d ...)).

more

Thank you very much for your input on this.

( 2017-01-09 10:03:56 -0500 )edit

The command limit is used to take limits of functions, not to set limits on definite integrals. You're probably looking for the command

f.integral(t,0,t)


Once the limit command is removed and this is put in, Maxima (the package used to evaluate integrals in SageMath) will ask you some questions about variable values. You can set those using the assume command.

You can also evaluate the integral by getting the indefinite integral and subtracting the value at zero using the subs command. Here's the code for both ways of doing this, including assumptions needed to get an answer back from Maxima:

var('c,H,k,d,x,t')
assume(H>0, d>0, t>0, e^(c*k*t/d)-1>0)

f=(c * H * (sech(k / d * (x - c * t))^2))/(d + H * (sech(k / d*(x - c * t))^2))

show( f.integral(t,0,t) )

int = f.integral(t)
show( int - int.subs(t=0) )


The show command just makes the output look better: here's a live example of the two results. They look different, but if you assign numerical values to variables and plot them you'll find they're the same. The second is a bit more simplified and may be more useful.

more

Thank you very much for your help and clarifications. One question, why did you set e^(ckt/d)-1>0 ?

( 2017-01-10 07:10:33 -0500 )edit

Because it was one of the questions asked by Maxima. Take out arguments of the assume command and you'll see the various questions.

( 2017-01-10 13:08:34 -0500 )edit

Thank you very much for all your help.

( 2017-01-11 04:48:23 -0500 )edit