Ask Your Question
1

quick latex question

asked 2018-03-19 19:25:22 +0100

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?

thx

see sage cell link text

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-03-21 14:27:07 +0100

slelievre gravatar image

updated 2018-03-21 15:02:00 +0100

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.

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

Stats

Asked: 2018-03-19 19:25:22 +0100

Seen: 714 times

Last updated: Mar 21 '18