@sym: rewrite (f, how) ¶Rewrite a symbolic expression.
Attempts to rewrite an expression f in terms of functions indicated by the case-sensitive string how.
Examples using trigonometry:
syms x
rewrite(exp(x), 'sin')
⇒ ans = (sym) sinh(x) + cosh(x)
rewrite(sin(x), 'exp')
⇒ ans = (sym)
⎛ ⅈ⋅x -ⅈ⋅x⎞
-ⅈ⋅⎝ℯ - ℯ ⎠
──────────────────
2
Often sincos is more useful than sin or cos:
rewrite(tan(x), 'sin')
⇒ (sym)
2
2⋅sin (x)
─────────
sin(2⋅x)
rewrite(tan(x), 'sincos')
⇒ (sym)
sin(x)
──────
cos(x)
The argument f can be a matrix:
rewrite([exp(x) cos(x) asin(x)], 'log')
⇒ ans = (sym 1×3 matrix)
⎡ ⎛ ________⎞⎤
⎢ x ⎜ ╱ 2 ⎟⎥
⎣ℯ cos(x) -ⅈ⋅log⎝ⅈ⋅x + ╲╱ 1 - x ⎠⎦
(and note that some elements of f might be unchanged.)
Example using integrals:
syms f(t) s
G = laplace(f)
⇒ G = (sym) LaplaceTransform(f(t), t, s)
rewrite(G, 'Integral')
⇒ ans = (sym)
∞
⌠
⎮ -s⋅t
⎮ f(t)⋅ℯ dt
⌡
0
Note the case-sensitivity of how:
use Integral not integral.
Further examples:
syms n r rewrite(factorial(n), 'gamma') ⇒ ans = (sym) Γ(n + 1)
nCr = nchoosek(n, r)
⇒ nCr = (sym)
⎛n⎞
⎜ ⎟
⎝r⎠
rewrite(nCr, 'factorial')
⇒ ans = (sym)
n!
───────────
r!⋅(n - r)!
See also: @@sym/simplify, @@sym/expand, @@sym/factor.
Package: symbolic