Processing math: 100%
Ask Your Question
2

Pretty print derivative in Newton notation with dot?

asked 4 years ago

sandy_scott gravatar image

updated 4 years ago

slelievre gravatar image

Is there any way to get the pretty printer to produce Newton's notation? - ie. a single dot centred over the variable for first derivative with respect to time, 2 dots for second derivative etc.

Example:

t, y = var('t, y')
x = function('x')(t)
pretty_print(y == 2*diff(diff(x,t),t) - 3 * diff(x,t) + 5)

gives:

sage math output

but I'd like to see:

Newton's Notation

Preview: (hide)

Comments

Welcome to Ask Sage! Thank you for your question!

slelievre gravatar imageslelievre ( 4 years ago )

Ideally, add

  • an example of input that one can paste in a fresh Sage session
  • the current output
  • the desired output
slelievre gravatar imageslelievre ( 4 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 4 years ago

slelievre gravatar image

updated 4 years ago

This gets requested from time to time and we should support that!

Not sure the pretty printer can do that, but there are workarounds.

One of them consists in defining "x dot" and "x dot dot" functions, and to substitute them in the equation.

sage: t, y = SR.var('t, y')
sage: x = function('x')(t)
sage: xdot = function('xdot', latex_name=r'\dot x')
sage: xddot = function('xddot', latex_name=r'\ddot x')
sage: de = y == 2*diff(diff(x, t), t) - 3 * diff(x, t) + 5
sage: dde = de.subs({diff(x, t): xdot(t), diff(diff(x, t), t): xddot(t)})
sage: view(dde)

y=2¨x(t)3˙x(t)+5

Even better, when defining a function, you can say what its derivative is.

Using that, start by defining the furthest derivative you'll need (here xdd for "x dot dot"), then work backwards until you define x.

Then the pretty printer gets things right without the need for subs.

sage: t, y = SR.var('t, y')
sage: xdd = function('xdd', latex_name=r'\ddot x')
sage: xd = function('xd', latex_name=r'\dot x',
....:               derivative_func=lambda self, *aa, **ka: xdd(*aa))
sage: x = function('x', derivative_func=lambda self, *aa, **ka: xd(*aa))
sage: de = y == 2*diff(diff(x(t), t), t) - 3 * diff(x(t), t) + 5
sage: view(de)

y=3˙x(t)+2¨x(t)+5

Preview: (hide)
link

Comments

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: 4 years ago

Seen: 913 times

Last updated: Dec 30 '20