Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taylor Coefficients for multivariate Functions #95

Open
LeanderK opened this issue Feb 25, 2025 · 1 comment
Open

Taylor Coefficients for multivariate Functions #95

LeanderK opened this issue Feb 25, 2025 · 1 comment

Comments

@LeanderK
Copy link

Hi, i wonder whether I can use this to compute the taylor coefficients for multivariate function up to a certain order. Right now, it takes a direction-parameter so it's really just univariate taylor coefficients as far as I understand. For my use-case, I am interested in all the combinations as I need it over all parameters. Thanks!

@tansongchen
Copy link
Member

TaylorDiff.jl is in principle nestable, which means that you can do this:

using TaylorDiff

f(x, y) = exp(x) * exp(y)
x0, y0 = 0., 0.
x_dx = TaylorScalar{2}(x0, one(x0))
x_dxdy = TaylorScalar{2}(x_dx, zero(x_dx))
y_dx = TaylorScalar{2}(y0, zero(y_0))
y_dxdy = TaylorScalar{2}(y_dx, one(y_dx))
result = f(x_dxdy, y_dxdy)

which gives you

TaylorScalar{TaylorScalar{Float64, 2}, 2}(TaylorScalar{Float64, 2}(1.0, (1.0, 0.5)), (TaylorScalar{Float64, 2}(1.0, (1.0, 0.5)), TaylorScalar{Float64, 2}(0.5, (0.5, 0.25))))

and if you run this

map(TaylorDiff.flatten, TaylorDiff.flatten(result))

you can conveniently get all the normalized coefficients of

((1.0, 1.0, 0.5), (1.0, 1.0, 0.5), (0.5, 0.5, 0.25))

which correspond to ((f, dfdx, dfdx2), (dfdy, dfdxy, dfdx2y), ...)


That being said, nested calculations are not tested rigorously, so some bugs might be there. Welcome any feedbacks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants