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.Thu, 19 Oct 2023 13:56:35 +0200How to define *complex* symbolic variableshttps://ask.sagemath.org/question/73938/how-to-define-complex-symbolic-variables/Hello,
I am quite new with SageMath, and I don't succeed in defining *complex* symbolic variables.
In the following example, SageMath seems to compute as if the variables were real (and not complex) :
var('w_2')
T=Matrix([[0, w_2], [0,0]])
S=T*(T.H)
S.eigenvalues()
The output of this command is
[w_2^2, 0]
whereas the expected result was
[norm(w_2), 0]
How can I tell SageMath that my symbolic variables are complex ones ?
Thanks in advance for your help !Thu, 19 Oct 2023 10:12:14 +0200https://ask.sagemath.org/question/73938/how-to-define-complex-symbolic-variables/Answer by eric_g for <p>Hello,</p>
<p>I am quite new with SageMath, and I don't succeed in defining <em>complex</em> symbolic variables.</p>
<p>In the following example, SageMath seems to compute as if the variables were real (and not complex) :</p>
<pre><code>var('w_2')
T=Matrix([[0, w_2], [0,0]])
S=T*(T.H)
S.eigenvalues()
</code></pre>
<p>The output of this command is </p>
<pre><code>[w_2^2, 0]
</code></pre>
<p>whereas the expected result was</p>
<pre><code>[norm(w_2), 0]
</code></pre>
<p>How can I tell SageMath that my symbolic variables are complex ones ?</p>
<p>Thanks in advance for your help !</p>
https://ask.sagemath.org/question/73938/how-to-define-complex-symbolic-variables/?answer=73939#post-id-73939Like this:
var('w_2', domain='complex')
The output of your code then becomes:
[w_2*conjugate(w_2), 0]Thu, 19 Oct 2023 11:06:04 +0200https://ask.sagemath.org/question/73938/how-to-define-complex-symbolic-variables/?answer=73939#post-id-73939Comment by endomorphisme59 for <p>Like this:</p>
<pre><code>var('w_2', domain='complex')
</code></pre>
<p>The output of your code then becomes:</p>
<pre><code>[w_2*conjugate(w_2), 0]
</code></pre>
https://ask.sagemath.org/question/73938/how-to-define-complex-symbolic-variables/?comment=73941#post-id-73941Thank you :)Thu, 19 Oct 2023 13:56:35 +0200https://ask.sagemath.org/question/73938/how-to-define-complex-symbolic-variables/?comment=73941#post-id-73941