Function Repository Resource:

MultivariateTaylorPolynomial

Source Notebook

Generate a multivariate Taylor polynomial of a given total degree

Contributed by: Daniel Lichtblau

ResourceFunction["MultivariateTaylorPolynomial"][func,vars,n]

computes the degree n multivariate Taylor polynomial of func in vars.

ResourceFunction["MultivariateTaylorPolynomial"][func,vars]

computes the multivariate Taylor polynomial of degree 1.

Details and Options

The degree n is the maximal total degree of the terms in the result.
When n is set to 1, the result is the constant term plus the linear terms in all variables.
Each entry in vars can be a variable or a list of the form {var,basepoint}. ResourceFunction["MultivariateTaylorPolynomial"] will expand each variable around its respective base point.
Any base point not explicitly provided is taken to be 0.
If a basepoint is infinite, the expansion will use its reciprocal and expand around the origin.
ResourceFunction["MultivariateTaylorPolynomial"] takes the same options as Series, with the additional option Weights{w1,w2,}. This gives an expansion where the total degree of all terms is weighted by the vector {w1,w2,}. If the variables are {v1,v2,} then any term v1e1v2e2 in the result satisfies the inequality w1e1+w2e2+<=n.

Examples

Basic Examples (3) 

Compute a multivariate Taylor polynomial of degree 4:

In[1]:=
ee = Sin[x + y^2];
mm = ResourceFunction["MultivariateTaylorPolynomial"][ee, {x, y}, 4]
Out[2]=

Check the result numerically:

In[3]:=
rep = {x -> .1, y -> -.2};
{ee, mm} /. rep
Out[4]=

Compute constant and linear terms of an expression expanded at {x=0,y=2}:

In[5]:=
ee = (Sin[1 + x + y^2] + Cos[1 - x^2 + y])*Exp[x^2*y];
mm = ResourceFunction["MultivariateTaylorPolynomial"][ee, {x, {y, 2}}]
Out[6]=

Compute a multivariate Taylor polynomial around {x=1,y=-2}:

In[7]:=
ee = Sin[x + y^2];
mm = ResourceFunction["MultivariateTaylorPolynomial"][
  ee, {{x, 1}, {y, -2}}, 4]
Out[8]=

Check the result numerically:

In[9]:=
rep = {x -> 1.2, y -> -2.1};
{ee, mm} /. rep
Out[10]=

Scope (2) 

MultivariateTaylorPolynomial can expand variables at infinity:

In[11]:=
ee = Sin[x^2 + y]*Sqrt[1/(1 + z^2)];
mm1 = ResourceFunction["MultivariateTaylorPolynomial"][
  ee, {{x, 0}, {y, -2}, {z, Infinity}}, 4]
Out[12]=

Providing Assumptions can simplify the computations and results:

In[13]:=
mm2 = ResourceFunction["MultivariateTaylorPolynomial"][
  ee, {{x, 0}, {y, -2}, {z, Infinity}}, 4, Assumptions -> {z > 1000, -3 < y < -2, 0 < x < 1}]
Out[13]=

Check these results numerically:

In[14]:=
rep = {x -> .01, y -> -2.01, z -> 11.1};
{ee, mm1, mm2} /. rep
Out[15]=

MultivariateTaylorPolynomial can give results that have asymptotic terms such as exponentials and implicit piecewise terms:

In[16]:=
ee = Sin[x]*Erf[z];
mm1 = ResourceFunction["MultivariateTaylorPolynomial"][
  ee, {{x, 0}, {z, Infinity}}, 4]
Out[17]=

Provide Assumptions to obtain a simpler result:

In[18]:=
mm2 = ResourceFunction["MultivariateTaylorPolynomial"][
  ee, {{x, 0}, {z, Infinity}}, 4, Assumptions -> {z > 1000, 1 < y < 3, 0 < x < 1}]
Out[18]=

Check these results numerically:

In[19]:=
rep = {x -> .01, z -> 11.1};
{ee, mm1, mm2} /. rep
Out[20]=

Expand at z=-:

In[21]:=
mm3 = ResourceFunction["MultivariateTaylorPolynomial"][
  ee, {{x, 0}, {z, -Infinity}}, 4]
Out[21]=

Check numerically:

In[22]:=
rep = {x -> .01, z -> -11.1};
{ee, mm3} /. rep
Out[23]=

Options (3) 

Weights (3) 

Compute a multivariate expansion to seventh order:

In[24]:=
ee = Sin[x + y^2]*Erf[z];
order = 7;
mm = ResourceFunction["MultivariateTaylorPolynomial"][ee, {x, y, z}, order]
Out[25]=

Use weights of {1,3,2} on the variables {x,y,z} respectively:

In[26]:=
mm2 = ResourceFunction["MultivariateTaylorPolynomial"][ee, {x, y, z}, order, Weights -> {1, 3, 2}]
Out[26]=

Use weights of on the variables {x,y,z} respectively:

In[27]:=
mm3 = ResourceFunction["MultivariateTaylorPolynomial"][ee, {x, y, z}, order, Weights -> {1, 1/3, 1/2}]
Out[27]=

Properties and Relations (2) 

Compute a multivariate Taylor polynomial of total degree 4:

In[28]:=
ee = Sin[x + y^2] - Cos[x^2 + y];
mm = Expand[
  ResourceFunction["MultivariateTaylorPolynomial"][ee, {x, y}, 4]]
Out[29]=

One can use Series to recover all terms by expanding in x and y separately to order 4, but this gives extra terms:

In[30]:=
Expand[Normal[Series[ee, {x, 0, 4}, {y, 0, 4}]]]
Out[30]=

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.0 – 09 August 2023

Related Resources

License Information