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.Tue, 09 Mar 2021 15:03:34 +0100The variable cannot be assigned a numberhttps://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/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
XiangruThu, 04 Mar 2021 21:58:54 +0100https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/Answer by Emmanuel Charpentier for <p>I simplify the codes as below:</p>
<pre><code>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)
</code></pre>
<p>when I do </p>
<pre><code>hkti(t=T)
</code></pre>
<p>It is OK, but when I want to assign an integer or real number, there is a problem</p>
<pre><code>hkti(t=0)
</code></pre>
<p>or </p>
<pre><code>hkti(t=0.0)
</code></pre>
<p>The error reads:</p>
<pre><code>AttributeError: 'sage.rings.integer.Integer' object has no attribute 'variables'
</code></pre>
<p>or</p>
<pre><code>AttributeError: 'sage.rings.real_mpfr.RealLiteral' object has no attribute 'variables'
</code></pre>
<p>It annoys me, could someone help me on this?</p>
<p>Thanks
Xiangru</p>
https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?answer=56026#post-id-56026The 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,
Fri, 05 Mar 2021 11:01:40 +0100https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?answer=56026#post-id-56026Comment by Tron for <p>The problem is that <code>hkti</code> is an <em>unevaluated</em> <code>integrate</code> expression, where <code>t</code> appears <em>both</em> in the expression to be integrated and the integration variable. The <code>(t=something</code>) substitution <em>blindly</em> substitutes <code>something</code> to <code>t</code> in both...</p>
<ul>
<li><p><code>hkti(t=T)</code> will become <code>integrate(sin(A*cos(2*pi*T/T) + kx), T)</code> (i.e. <code>integrate(sin(A*cos(2*pi*1) + kx), T)</code>, then <code>integrate(sin(A+kx), T)</code>, i.e. trivially <code>T*sin(A+kx)</code>). Probably <strong>not</strong> what you mean...</p></li>
<li><p><code>hkti(t=0)</code>will become <code>integrate(sin(A*cos(2*pi*0/T) + kx), 0)</code>, which is nonsense (there is no such thing as an integration with respect to a constant...).</p></li>
</ul>
<p>What is the problem you are trying to solve ?</p>
<p>HTH,</p>
https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?comment=56071#post-id-56071Hi Emmnuel, thanks very much. I must digest your information first! :)Tue, 09 Mar 2021 15:03:34 +0100https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?comment=56071#post-id-56071Comment by Emmanuel Charpentier for <p>The problem is that <code>hkti</code> is an <em>unevaluated</em> <code>integrate</code> expression, where <code>t</code> appears <em>both</em> in the expression to be integrated and the integration variable. The <code>(t=something</code>) substitution <em>blindly</em> substitutes <code>something</code> to <code>t</code> in both...</p>
<ul>
<li><p><code>hkti(t=T)</code> will become <code>integrate(sin(A*cos(2*pi*T/T) + kx), T)</code> (i.e. <code>integrate(sin(A*cos(2*pi*1) + kx), T)</code>, then <code>integrate(sin(A+kx), T)</code>, i.e. trivially <code>T*sin(A+kx)</code>). Probably <strong>not</strong> what you mean...</p></li>
<li><p><code>hkti(t=0)</code>will become <code>integrate(sin(A*cos(2*pi*0/T) + kx), 0)</code>, which is nonsense (there is no such thing as an integration with respect to a constant...).</p></li>
</ul>
<p>What is the problem you are trying to solve ?</p>
<p>HTH,</p>
https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?comment=56034#post-id-56034Note : 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](https://math.stackexchange.com/questions/1196401/what-are-besselj-functions) and [here](https://math.stackexchange.com/questions/1047067/what-is-the-integral-of-sin-cos-x).
No idea (tonight...) on how to proceed with `A!=1$, sorry...Sat, 06 Mar 2021 00:32:25 +0100https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?comment=56034#post-id-56034Comment by Emmanuel Charpentier for <p>The problem is that <code>hkti</code> is an <em>unevaluated</em> <code>integrate</code> expression, where <code>t</code> appears <em>both</em> in the expression to be integrated and the integration variable. The <code>(t=something</code>) substitution <em>blindly</em> substitutes <code>something</code> to <code>t</code> in both...</p>
<ul>
<li><p><code>hkti(t=T)</code> will become <code>integrate(sin(A*cos(2*pi*T/T) + kx), T)</code> (i.e. <code>integrate(sin(A*cos(2*pi*1) + kx), T)</code>, then <code>integrate(sin(A+kx), T)</code>, i.e. trivially <code>T*sin(A+kx)</code>). Probably <strong>not</strong> what you mean...</p></li>
<li><p><code>hkti(t=0)</code>will become <code>integrate(sin(A*cos(2*pi*0/T) + kx), 0)</code>, which is nonsense (there is no such thing as an integration with respect to a constant...).</p></li>
</ul>
<p>What is the problem you are trying to solve ?</p>
<p>HTH,</p>
https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?comment=56033#post-id-56033None of the CASes I have access to (Sage, Sympy, Giac, Fricas, Mathematica (with or without [Rubi](https://rulebasedintegration.org/))) 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?`Fri, 05 Mar 2021 23:04:19 +0100https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?comment=56033#post-id-56033Comment by Tron for <p>The problem is that <code>hkti</code> is an <em>unevaluated</em> <code>integrate</code> expression, where <code>t</code> appears <em>both</em> in the expression to be integrated and the integration variable. The <code>(t=something</code>) substitution <em>blindly</em> substitutes <code>something</code> to <code>t</code> in both...</p>
<ul>
<li><p><code>hkti(t=T)</code> will become <code>integrate(sin(A*cos(2*pi*T/T) + kx), T)</code> (i.e. <code>integrate(sin(A*cos(2*pi*1) + kx), T)</code>, then <code>integrate(sin(A+kx), T)</code>, i.e. trivially <code>T*sin(A+kx)</code>). Probably <strong>not</strong> what you mean...</p></li>
<li><p><code>hkti(t=0)</code>will become <code>integrate(sin(A*cos(2*pi*0/T) + kx), 0)</code>, which is nonsense (there is no such thing as an integration with respect to a constant...).</p></li>
</ul>
<p>What is the problem you are trying to solve ?</p>
<p>HTH,</p>
https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?comment=56032#post-id-56032Thanks 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.Fri, 05 Mar 2021 15:14:45 +0100https://ask.sagemath.org/question/56024/the-variable-cannot-be-assigned-a-number/?comment=56032#post-id-56032