如何在 sympy 中更改函数导数的打印表示 [英] How to change printed representation of function's derivative in sympy

查看:36
本文介绍了如何在 sympy 中更改函数导数的打印表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在动态系统中,我的基本值都是时间的函数,d(t).我创建变量 d 使用 d = Function('d')(t) where t = S('t')

In a dynamic system my base values are all functions of time, d(t). I create the variable d using d = Function('d')(t) where t = S('t')

显然,d 的导数(速度等变化率)是很常见的.但是 diff(d(t)) 的默认打印给出:-

Obviously it's very common to have derivatives of d (rates of change like velocity etc.). However the default printing of diff(d(t)) gives:-

Derivative(d(t), t)

并在 ipython 中使用漂亮的打印(例如)可以提供更好看的版本:-

and using pretty printing in ipython (for e.g.) gives a better looking version of:-

d/dt (d(t))

包含 d(t) 导数的函数在我的问题中相当长,我希望打印的表示类似于 d'(t)\dot(d)(t)(乳胶).

The functions which include the derivatives of d(t) are fairly long in my problems however, and I'd like the printed representation to be something like d'(t) or \dot(d)(t) (Latex).

这在 sympy 中可能吗?我可能可以使用 subs 解决这个问题,但更喜欢通用的 sympy_print 函数或我可以调整的东西.

Is this possible in sympy? I can probably workaround this using subs but would prefer a generic sympy_print function or something I could tweak.

推荐答案

矢量打印 模块是在 SymPy 中实现此类打印的唯一地方.

The vector printing module that you already found is the only place where such printing is implemented in SymPy.

from sympy.physics.vector import dynamicsymbols
from sympy.physics.vector.printing import vpprint, vlatex
d = dynamicsymbols('d')
vpprint(d.diff())     # ḋ
vlatex(d.diff())      # '\\dot{d}'

常规打印机(pretty、LaTeX 等)不支持导数的素数或点表示法.它们的 _print_Derivative 方法被编写成它们也适用于多变量表达式,其中必须使用某种 d/dx 符号来指定一个变量.

The regular printers (pretty, LaTeX, etc) do not support either prime or dot notation for derivatives. Their _print_Derivative methods are written so that they also work for multivariable expressions, where one has to specify a variable by using some sort of d/dx notation.

一般来说,如果可以选择更短的导数表示法会很好.

It would be nice to have an option for shorter derivative notation in general.

这篇关于如何在 sympy 中更改函数导数的打印表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆