Ask Your Question

# Symbolic Taylor expansion

I would like to expand the symbol function $f$ as a Taylor series $$\delta f(x)=\delta x\frac{d}{dx}f+\frac12(\delta x)^2\frac{d^2}{dx^2}f+O((\delta x)^3)$$ with $$\delta x = a_1(\delta t)^{\frac12}+a_2(\delta t)+a_3(\delta t)^{\frac32}+O((\delta t)^2)$$ and expand and collect the same power terms of $\delta t$ up to a designated power, say, $\frac32$. $f$ is just a symbol, I just need Mathsage to produce the symbols of derivatives $\frac{d}{dx}$.

How should one set this up?

Inspired by eric_g's answer to this question, I am able to perform the same operation to $f(x,y)$ with $$\delta y = a_1(\delta s)^{\frac12}+a_2(\delta s)+a_3(\delta s)^{\frac32}+O((\delta s)^2)$$. I would like to collect terms according to the powers $dt^{\frac i2}ds^{\frac j2}$ where $i$ and $j$ are nonnegative integers and arranged in the ascending order of $i+j$. I would also like to have the capacity to collect terms according to the order of some other variables, say, $a_1$. I have tried using

g.full_simplify().maxima_methods().collectterms(dt)

for a single variable $dt$. But it does not seem to work well for the fractional power. I do not know if it will work for $dt^{\frac i2}ds^{\frac j2}$.

How can I set this up?

edit retag close merge delete

## 2 answers

Sort by » oldest newest most voted

You can do

sage: f = function('f')
sage: var('h dt a1 a2 a3')
(h, dt, a1, a2, a3)
sage: dx = a1*h + a2*h^2 + a3*h^3
sage: s = taylor(f(x+dx), h, 0, 3); s
1/6*(a1^3*diff(f(x), x, x, x) + 6*a1*a2*diff(f(x), x, x) + 6*a3*diff(f(x), x))*h^3 + 1/2*(a1^2*diff(f(x), x, x) + 2*a2*diff(f(x), x))*h^2 + a1*h*diff(f(x), x) + f(x)
sage: sdt = s.subs({h: dt^(1/2)}); sdt
1/6*(a1^3*diff(f(x), x, x, x) + 6*a1*a2*diff(f(x), x, x) + 6*a3*diff(f(x), x))*dt^(3/2) + a1*sqrt(dt)*diff(f(x), x) + 1/2*(a1^2*diff(f(x), x, x) + 2*a2*diff(f(x), x))*dt + f(x)
sage: view(sdt)


$\frac{1}{6} {\left(a_{1}^{3} \frac{\partial^{3}}{(\partial x)^{3}}f\left(x\right) + 6 a_{1} a_{2} \frac{\partial^{2}}{(\partial x)^{2}}f\left(x\right) + 6 a_{3} \frac{\partial}{\partial x}f\left(x\right)\right)} \mathit{dt}^{\frac{3}{2}} + a_{1} \sqrt{\mathit{dt}} \frac{\partial}{\partial x}f\left(x\right) + \frac{1}{2} {\left(a_{1}^{2} \frac{\partial^{2}}{(\partial x)^{2}}f\left(x\right) + 2 a_{2} \frac{\partial}{\partial x}f\left(x\right)\right)} \mathit{dt} + f\left(x\right)$

more

## Comments

Excellent! Is there a way to expand using $\delta t$ directly without going through $h$? Also I would like to generalize this to the second half of my newly edited question. Could you please review my question? Thank you.

( 2018-10-31 15:46:08 -0500 )edit

Does this :

sage: f=function("f")
sage: latex(diff(f(x),x))
\frac{\partial}{\partial x}f\left(x\right)


answers your question ?

more

## Comments

Well, that would be part of the solution. But I want a multiple term expansion of the Taylor series then substituting in the expansion of $\delta x$. The latex command is nice, though. I can use it at the last command to present the result better.

( 2018-10-31 15:42:43 -0500 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2018-10-30 20:08:34 -0500

Seen: 236 times

Last updated: Oct 31 '18