Ask Your Question
0

sagemath displays in different lines

asked 2022-11-23 21:20:39 +0100

Flopsiturtle gravatar image

Hi there,

I am trying to display two different things at once. The first is some Latex stuff, and the second is the solution to a symbolic integration done in sage. Here is the code:

eq2 = x*eq0

display(LatexExpr(r'\langle x \rangle = \int\limits_{-\infty}^\infty x\rho dx'))

x1 = eq2.rhs().integral(x, -infinity, infinity)

display(LatexExpr(r'\langle x\rangle = '), x1)

(sorry I don't know how to show my code in a better format) so what happens is, that the latex expression is displayed in the first line and x1 is displayed in the second line. I hope someone can help me with this.

P.S.: is there a way to display the integral itself and not only the solution? I avoided this problem by just writing the latex expression manually in the first line. Thanks in advance for your help :)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2022-11-23 22:31:19 +0100

achrzesz gravatar image

updated 2022-11-24 03:54:23 +0100

Maybe this example can help

%display latex
C=var('C')
show(integrate(tan(x),x,hold=True),'=', integrate(tan(x),x),'+',C)
edit flag offensive delete link more

Comments

Thanks it works like this

Flopsiturtle gravatar imageFlopsiturtle ( 2022-11-24 14:41:23 +0100 )edit
0

answered 2022-11-24 03:28:27 +0100

Juanjo gravatar image

Try the following examples:

expression = r"\displaystyle\int_0^{\pi/4}\tan(x)\,dx ="
result = integrate(tan(x), (x,0,pi/4))
show(html("$" + expression + f"{latex(result)}" + "$"))

expression = r"\displaystyle\lim_{x\to 0}\frac{\sin^2(\pi x)}{x^2}="
result = limit(sin(pi*x)^2/x^2, x=0)
show(html("$" + expression + f"{latex(result)}" + "$"))

They are shown in this SageMath Cell

edit flag offensive delete link more

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: 2022-11-23 21:20:39 +0100

Seen: 326 times

Last updated: Nov 24 '22