1 | initial version |
2 | No.2 Revision |
Duplicate 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)
show(DEQ)
print(latex(DEQ))
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.
3 | No.3 Revision |
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)
show(DEQ)
print(latex(DEQ))
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.