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, 23 Apr 2020 03:49:30 +0200Pb with unicode characterhttps://ask.sagemath.org/question/50931/pb-with-unicode-character/ The following code works perfectly
var("w0, pi, D, I")
A = matrix(SR, 2, 2, [[w0, 1],[w0-pi,1]])
y = vector([w0-D, w0-D-pi+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, pi, I, w0)=sola*x + solb
show("f(x, D, pi, I, w0)=", f(x, D, pi, I, w0))
But if I use \pi <TAB> in replacement of pi, there is a Macsyma error
Wed, 22 Apr 2020 23:03:10 +0200https://ask.sagemath.org/question/50931/pb-with-unicode-character/Comment by dsejas for <p>The following code works perfectly</p>
<pre><code>var("w0, pi, D, I")
A = matrix(SR, 2, 2, [[w0, 1],[w0-pi,1]])
y = vector([w0-D, w0-D-pi+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, pi, I, w0)=sola*x + solb
show("f(x, D, pi, I, w0)=", f(x, D, pi, I, w0))
</code></pre>
<p>But if I use \pi <tab> in replacement of pi, there is a Macsyma error</p>
https://ask.sagemath.org/question/50931/pb-with-unicode-character/?comment=50937#post-id-50937Hello, @Cyrille! Unfortunately, I don't have a complete solution for this problem, so I am writing just a comment.
The problem seems to be in the `full_simplify()` command. Reading the code of this command, I can see that, eventually, it has to convert the Sage code to Maxima code, and, unfortunately, Maxima doesn't handle Unicode characters, like Greek letters. You can try this in order to reproduce the error:
\pi<TAB>._maxima_()
If all you want is to have the output written in LaTeX code, you can use the command `pi = var("pi", latex_name=r"\pi")`. Notice the letter `r` before the double-quote signs in the `latex_name` argument? That is in order to tell Sage to avoid executing the backslash, which is a escape-character for Python. That is called a raw string (thus the `r`)Thu, 23 Apr 2020 03:42:26 +0200https://ask.sagemath.org/question/50931/pb-with-unicode-character/?comment=50937#post-id-50937Comment by dsejas for <p>The following code works perfectly</p>
<pre><code>var("w0, pi, D, I")
A = matrix(SR, 2, 2, [[w0, 1],[w0-pi,1]])
y = vector([w0-D, w0-D-pi+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, pi, I, w0)=sola*x + solb
show("f(x, D, pi, I, w0)=", f(x, D, pi, I, w0))
</code></pre>
<p>But if I use \pi <tab> in replacement of pi, there is a Macsyma error</p>
https://ask.sagemath.org/question/50931/pb-with-unicode-character/?comment=50938#post-id-50938This is the modified code:
var("w0, D, I")
pi = var("pi", latex_name=r"\pi")
A = matrix(SR, 2, 2, [[w0, 1],[w0-pi,1]])
y = vector([w0-D, w0-D-pi+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, pi, I, w0)=sola*x + solb
show("f(x, D," + latex(pi) + ", I, w0)=", f(x, D, pi, I, w0))
This is the result:
$$\newcommand{\Bold}[1]{\mathbf{#1}}f(x, D, {\pi} , I, w0)= -\frac{{\left(I - {\pi}\right)} x}{{\pi}} - \frac{D {\pi} - I w_{0}}{{\pi}}$$
In any case, using the `latex_name` argument should produce better results than using Unicode characters, since these are written with LaTeX's `\verb`, which is intended for verbatim text, and disrupts the math-mode.Thu, 23 Apr 2020 03:49:30 +0200https://ask.sagemath.org/question/50931/pb-with-unicode-character/?comment=50938#post-id-50938