Ask Your Question

quick latex question

asked 2018-03-19 13:25:22 -0500

userX gravatar image

I am writing a worksheet for an ODE course and would like to display the following equation as $$y''+y=1$$ OR as $$\frac{d^2y}{dx^2}+y=1$$ However sage always reverts to partials. Is there an easy way to display these as ordinary differential equations?


see sage cell link text

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-03-21 08:27:07 -0500

slelievre gravatar image

updated 2018-03-21 09:02:00 -0500

Possibly a duplicate of

A quick and dirty workaround would be to replace your original code:

x   = var('x')
y   = function('y')(x)
DEQ = diff(y,x) + y - 1 == 0
sol = desolve(DEQ, y)


by something along the lines of:

sage: x = SR.var('x')
sage: y = function('y')(x)
sage: de = diff(y, x) + y - 1 == 0
sage: de
y(x) + diff(y(x), x) - 1 == 0

sage: y1 = function("y'")(x)
sage: de_pretty = de.substitute({diff(y, x): y1})
sage: de_pretty
y(x) + y'(x) - 1 == 0

and running show or view or latex on de_pretty rather than de.

One could write a function to prettify differential equations, by parsing the expression tree of the differential equation, and substituting derivatives by aptly named replacement functions.

One would then run desolve on the original differential equation, and use the prettified equation for showing, viewing, latexing.

Or maybe it would be easier to work the other way! Start by defining the pretty differential equation, and substitute an actual differential equation for solving.

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


Asked: 2018-03-19 13:25:22 -0500

Seen: 49 times

Last updated: Mar 21