# The variable cannot be assigned a number

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

I simplify the codes as below:

var("T t kx A")
w = 2*pi/T
kt = kx + A*cos(w*t)
hkt = sin(kt)
show(hkt)
hkti = hkt.integral(t)
show(hkti)


when I do

hkti(t=T)


It is OK, but when I want to assign an integer or real number, there is a problem

hkti(t=0)


or

hkti(t=0.0)


AttributeError: 'sage.rings.integer.Integer' object has no attribute 'variables'


or

AttributeError: 'sage.rings.real_mpfr.RealLiteral' object has no attribute 'variables'


It annoys me, could someone help me on this?

Thanks Xiangru

edit retag close merge delete

Sort by » oldest newest most voted

The problem is that hkti is an unevaluated integrate expression, where t appears both in the expression to be integrated and the integration variable. The (t=something) substitution blindly substitutes something to t in both...

• hkti(t=T) will become integrate(sin(A*cos(2*pi*T/T) + kx), T) (i.e. integrate(sin(A*cos(2*pi*1) + kx), T), then integrate(sin(A+kx), T), i.e. trivially T*sin(A+kx)). Probably not what you mean...

• hkti(t=0)will become integrate(sin(A*cos(2*pi*0/T) + kx), 0), which is nonsense (there is no such thing as an integration with respect to a constant...).

What is the problem you are trying to solve ?

HTH,

more

Thanks for your reply. Yes, indeed, I kind of understand the problem. I am quite new to sage, and whta you said makes sense.

I was trying to find an integral definite_integrate(sin(A*cos(2*pi*T/T) + kx), 0, T). And now it seems that this can not be evaluated by sage. I will try to find another way to do this.

( 2021-03-05 15:14:45 +0200 )edit

None of the CASes I have access to (Sage, Sympy, Giac, Fricas, Mathematica (with or without Rubi)) is able to compute a primitive for this function. Two possible solutions for practical use of this integral :

• Numerical integration. For further symbolic computation involving this integral, create a new "special function" i. e. a symbolic function, suitably named and with an evalf property using numerical integration. See function? online help.

• If the range of variation of t is "small" wrt T, a Taylor development of suitable center and order, which is a polynomial "acceptable" approximation, can be integrated to a polynomial of known coefficients, possibly involving the other constants occurring in the original expression. See x.taylor?

( 2021-03-05 23:04:19 +0200 )edit

Note : in the special case A==1, your problem can be solved (awkwardly) in terms of Bessel and Struve functions (boith can be evaluated in Sage). See here and here.

No idea (tonight...) on how to proceed with `A!=1\$, sorry...

( 2021-03-06 00:32:25 +0200 )edit

Hi Emmnuel, thanks very much. I must digest your information first! :)

( 2021-03-09 15:03:34 +0200 )edit