Processing math: 100%
Ask Your Question
0

Symbolic Taylor expansion

asked 6 years ago

Hans gravatar image

updated 6 years ago

I would like to expand the symbol function f as a Taylor series δf(x)=δxddxf+12(δx)2d2dx2f+O((δx)3) with δx=a1(δt)12+a2(δt)+a3(δt)32+O((δt)2) and expand and collect the same power terms of δt up to a designated power, say, 32. f is just a symbol, I just need Mathsage to produce the symbols of derivatives ddx.

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 δy=a1(δs)12+a2(δs)+a3(δs)32+O((δs)2). I would like to collect terms according to the powers dti2dsj2 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, a1. 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 dti2dsj2.

How can I set this up?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 6 years ago

eric_g gravatar image

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)

16(a313(x)3f(x)+6a1a22(x)2f(x)+6a3xf(x))dt32+a1dtxf(x)+12(a212(x)2f(x)+2a2xf(x))dt+f(x)

Preview: (hide)
link

Comments

Excellent! Is there a way to expand using δ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.

Hans gravatar imageHans ( 6 years ago )
0

answered 6 years ago

Emmanuel Charpentier gravatar image

Does this :

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

answers your question ?

Preview: (hide)
link

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 δx. The latex command is nice, though. I can use it at the last command to present the result better.

Hans gravatar imageHans ( 6 years ago )

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

Seen: 2,118 times

Last updated: Nov 01 '18