Ask Your Question
0

The variable cannot be assigned a number

asked 2021-03-04 21:58:54 +0200

this post is marked as community wiki

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)

The error reads:

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-03-05 11:01:40 +0200

Emmanuel Charpentier gravatar image

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,

edit flag offensive delete link more

Comments

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.

Tron gravatar imageTron ( 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?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 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...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-03-06 00:32:25 +0200 )edit

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

Tron gravatar imageTron ( 2021-03-09 15:03:34 +0200 )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

1 follower

Stats

Asked: 2021-03-04 21:58:54 +0200

Seen: 68 times

Last updated: Mar 05