Taylor Expansion in Mathematica (Multivariate)

Click For Summary

Discussion Overview

The discussion revolves around the use of Mathematica for performing multivariate Taylor expansions of functions dependent on multiple variables, specifically four variables that are functions of time. Participants explore syntax issues, provide examples, and seek clarification on how Mathematica interprets these variables.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes an attempt to linearize a complex function of four variables using the Series function in Mathematica, noting issues with variable recognition.
  • Another participant requests a canonical example to better understand the problem, suggesting a simpler function for clarity.
  • A participant expresses that their function is too complicated to present fully but reiterates the main concern about Mathematica's ability to recognize all four variables for Taylor expansion.
  • Several participants discuss the importance of defining variables correctly in Mathematica, emphasizing that variables should not be treated as functions of time unless explicitly stated.
  • One participant provides an example of a function and its series expansion, questioning whether it aligns with the original poster's needs.
  • Another participant points out that the original poster may be confusing function names with variable names, suggesting a redefinition of variables to ensure proper series expansion.
  • There is a consensus among some participants that the misunderstanding lies in how the variables are defined and their dependency on time.
  • A later reply indicates that the original poster's adjustments to the variable definitions resolved some issues, although they still express uncertainty about the linearity of the results.

Areas of Agreement / Disagreement

Participants generally agree that the issue stems from the way variables are defined in Mathematica, but there is no consensus on the best approach to resolve the original poster's specific problem. Multiple competing views on variable definition and function structure remain.

Contextual Notes

Participants note limitations in the clarity of the original function and the complexity of the expressions involved, which may affect the ability to perform Taylor expansions accurately. There are also unresolved questions about the linearity of the resulting series expansions.

road_king
Messages
18
Reaction score
0
Hi!

I'm trying to linearize a function f which is dependent of 4 variables, each one dependent of time.

f[var1_,var2_,var3_,var4_]:= ... expression


I use Series[f, {var1,var10 ,1},{var2,var20 ,1},...] syntax
as I read on the documentation center.

The problem is that the program only read the 2 first variables as function variables (green colored) and the last 2 appeared in blue.

It causes me confusion because I thought Mathematica could do multivariate Taylor expansion...

Anyone has any idea of what is wrong? Thanks in advance.
 
Last edited:
Physics news on Phys.org
You need to give us a canonical example. Like:

f(a,b,c,d)=2a+3ab^2-c^3+\sin(d)

Ok, suppose it's that. Can Mathematica do even that? Now you said each of the variables are functions of t as in:

f(t)=2a(t)+3a(t)b(t)^2-c(t)^3+\sin(d(t))

Ok, suppose it's that. Not sure what you want at this point though.
 
Thank you very much Jackmell. That is basically the idea, but my function f is much more complicated than that. That is why it would be a very tedious work to write it in Latex.
I tried to export it with Mathematica function, but I have not got pretty satisfactory results.

So, let´s focus, the question is if Mathematica is able to do Taylor series expansion of f for all of the 4 variables. (In my expression, is like if only were able to recognize the first 2 as variables of f, i.e. in the function you wrote, a,b, but no for c,d)
 
road_king said:
Thank you very much Jackmell. That is basically the idea, but my function f is much more complicated than that. That is why it would be a very tedious work to write it in Latex.
I tried to export it with Mathematica function, but I have not got pretty satisfactory results.

So, let´s focus, the question is if Mathematica is able to do Taylor series expansion of f for all of the 4 variables. (In my expression, is like if only were able to recognize the first 2 as variables of f, i.e. in the function you wrote, a,b, but no for c,d)

Ok, that's what "canonical" means. You don't have to post your function, only a simple piece of it or something simple that looks kind of like it minus any unnecessary trappings like hard-to-read variables, unnecessary constant expressions, and the like.

Tell you what, the example above wasn't a good one. I'll use:

f(a,b,c,d)=a \sin(b+c)-\cos(ad) e^{ac}

Here's the code and result and note I first block the code, choose Cell/Convert To/Raw Input Form, then cut and paste it here so all the formatting is gone but at least it correctly presented:
Code:
In[15]:=
f[a_, b_, c_, d_] := a*Sin[b + c] - 
   Cos[d*a]*Exp[a*c]
Normal[Series[f[a, b, c, d], {a, 0, 5}, {b, 0, 5}, 
   {c, 0, 5}, {d, 0, 5}]]

Out[16]=
-1 + a*b - (a*b^3)/6 + (a*b^5)/120 + 
  (-((a*b^2)/2) + (a*b^4)/24)*c + 
  (-(a^2/2) - (a*b)/2 + (a*b^3)/12 - (a*b^5)/240)*
   c^2 + (-(a/6) - a^3/6 + (a*b^2)/12 - 
    (a*b^4)/144)*c^3 + (-(a^4/24) + (a*b)/24 - 
    (a*b^3)/144 + (a*b^5)/2880)*c^4 + 
  (a/120 - a^5/120 - (a*b^2)/240 + (a*b^4)/2880)*
   c^5 + (a^2/2 + (a^3*c)/2 + (a^4*c^2)/4 + 
    (a^5*c^3)/12)*d^2 + (-(a^4/24) - (a^5*c)/24)*d^4

Is this not what you want?
 
Last edited:
Thank you very much! That is exactly in the same syntax form I wrote. I will copy/paste but I think it will be useless

f[x_, \[Theta]_, \[Alpha]_, vm_] := ((1/(rm*rmp^2))*(7*(js + h^2*(mc + mp)) - 3*h^2*mp*Cos[\[Alpha][t]]^2 - 3*h*mp*Sin[2*\[Alpha][t]]*x[t] + (7*(mc + mp) - 3*mp*Sin[\[Alpha][t]]^2)*x[t]^2)*
(14*kg*kt*rmp*\[Eta]g*\[Eta]m*vm[t] - 2*Derivative[1][x][t]*(7*beq*rm*rmp^2 + 7*kg^2*km*kt*\[Eta]g*\[Eta]m - 3*mp*rm*rmp^2*Sin[2*\[Alpha][t]]*Derivative[1][\[Theta]][t]) +
rm*rmp^2*(g*((14*mc + 11*mp)*Sin[\[Theta][t]] - 3*mp*Sin[2*\[Alpha][t] + \[Theta][t]]) + 7*lp*mp*Sin[\[Alpha][t]]*Derivative[1][\[Alpha]][t]^2 +
14*lp*mp*Sin[\[Alpha][t]]*Derivative[1][\[Alpha]][t]*Derivative[1][\[Theta]][t] + (mp*(7*lp + 6*h*Cos[\[Alpha][t]])*Sin[\[Alpha][t]] + (14*mc + 11*mp - 3*mp*Cos[2*\[Alpha][t]])*x[t])*
Derivative[1][\[Theta]][t]^2)) + (h*(7*(mc + mp) - 3*mp*Cos[\[Alpha][t]]^2) - 3*mp*Cos[\[Alpha][t]]*Sin[\[Alpha][t]]*x[t])*
((-mp)*(7*lp + 6*h*Cos[\[Alpha][t]] + 6*Sin[\[Alpha][t]]*x[t])*((-g)*Sin[\[Alpha][t] + \[Theta][t]] + 2*Sin[\[Alpha][t]]*Derivative[1][x][t]*Derivative[1][\[Theta]][t] +
(h*Sin[\[Alpha][t]] - Cos[\[Alpha][t]]*x[t])*Derivative[1][\[Theta]][t]^2) - 7*(2*g*h*mc*Sin[\[Theta][t]] + 2*g*h*mp*Sin[\[Theta][t]] + 2*c*g*ms*Sin[\[Theta][t]] + g*lp*mp*Sin[\[Alpha][t] + \[Theta][t]] +
h*lp*mp*Sin[\[Alpha][t]]*Derivative[1][\[Alpha]][t]^2 - 2*lp*mp*Sin[\[Alpha][t]]*Derivative[1][x][t]*Derivative[1][\[Theta]][t] + 2*h*lp*mp*Sin[\[Alpha][t]]*Derivative[1][\[Alpha]][t]*
Derivative[1][\[Theta]][t] + x[t]*((-lp)*mp*Cos[\[Alpha][t]]*Derivative[1][\[Alpha]][t]^2 - 2*lp*mp*Cos[\[Alpha][t]]*Derivative[1][\[Alpha]][t]*Derivative[1][\[Theta]][t] +
2*(mc + mp)*(g*Cos[\[Theta][t]] - 2*Derivative[1][x][t]*Derivative[1][\[Theta]][t])))))/(7*(js*(14*mc + 11*mp - 3*mp*Cos[2*\[Alpha][t]]) + 2*(7*mc^2 + 11*mc*mp + 4*mp^2)*x[t]^2));

and that is the next order and the output

Normal[Series[f[x, \[Theta], \[Alpha], vm], {x, 0, 1}, {\[Theta], 0, 1}, {\[Alpha], 0, 1}, {vm, 0, 1}]]


f[0, 0, 0, 0] + x f [1, 0, 0, 0][0, 0, 0, 0] + θ (f [0, 1, 0, 0][0, 0, 0, 0] + x f [1, 1, 0, 0][0, 0, 0, 0]) +
α (f [0, 0, 1, 0] [0, 0, 0, 0] + x f [1, 0, 1, 0] [0, 0, 0, 0] + θ (f [0, 1, 1, 0] [0, 0, 0, 0] + x f[1, 1, 1, 0] [0, 0, 0, 0])) + vm (f (0,0,0,1) [0, 0, 0, 0] + x f (1,0,0,1) [0, 0, 0, 0] + θ (f (0,1,0,1) [0, 0, 0, 0] + x f (1,1,0,1) [0, 0, 0, 0]) + α(f (0,0,1,1) [0, 0, 0, 0] + x f (1,0,1,1) [0, 0, 0, 0] + θ(f (0,1,1,1) [0, 0, 0, 0] + x f (1,1,1,1) [0, 0, 0, 0])))
 
Looks like you're mixing up function names and variable names. Take a simple example:

f[a_]:=cos(a(t))

Then you attempt to compute the series in terms of a as:

Series[f[a],{a,0,5}]

I'm not sure how Mathematica is handling that. If I wanted a series in terms of t, I would write:

f[t_]:=cos(a(t))

then:

Series[f[t],{t,0,5}]

but not sure that's what you want.
 
Yeah this is a weird way of defining things.

If you want a series in "t" then you can just do that one series.

If you want a series in x, theta, alpha and vm, then they should NOT be defined as is:

f[a_]:= Cos[a[t]]

Means if I put f[Sin] I get Cos[Sin[t]]

Basically the variable is the FUNCTION "a" and not its value at that time "t".

EXAMPLE :

f[a_] := Cos[a[t]]
D[f[a], a]
D[f[a], a[t]]

The first is NOT what you want, the second IS. So your "variable" should be a[t] not "a".:

Normal[Series[
f[x, \[Theta], \[Alpha], vm], {x[t], 0, 1}, {\[Theta][t], 0,
1}, {\[Alpha][t], 0, 1}, {vm[t], 0, 1}]]
 
Hepth said:
Yeah this is a weird way of defining things.

If you want a series in "t" then you can just do that one series.

If you want a series in x, theta, alpha and vm, then they should NOT be defined as is:

f[a_]:= Cos[a[t]]

Means if I put f[Sin] I get Cos[Sin[t]]

Basically the variable is the FUNCTION "a" and not its value at that time "t".

EXAMPLE :

f[a_] := Cos[a[t]]
D[f[a], a]
D[f[a], a[t]]

The first is NOT what you want, the second IS. So your "variable" should be a[t] not "a".:

Normal[Series[
f[x, \[Theta], \[Alpha], vm], {x[t], 0, 1}, {\[Theta][t], 0,
1}, {\[Alpha][t], 0, 1}, {vm[t], 0, 1}]]

Thank you both very much!

It was the problem. (My misconception of what Mathematica undertood as variables... )

I put the expression in a explicit dependency of time form and It seems to work, although It was not linear at all ... ? I don't know why.

I add this:

Normal[Series[f1[x, θ,α, vm], {x[t], 0, 1}, {θ[t], 0, 1}, {α[t], 0, 1}, {vm[t], 0, 1}]] /. {Derivative[1][x][t] -> 0, Derivative[1][θ][t] -> 0,
Derivative[1][α][t] -> 0, Derivative[1][vm][t] -> 0}

in order to full linearize but the expression I get (after value subsitution) is this:

2459.07 (-0.000560617 α[t] + 0.000219434 vm[t] (2.84172 - 0.1725 x[t] α[t]) +
0.00372572 θ[t] + x[t] (-0.00100995 + 0.000296346 α[t] θ[t]))

where you could see that it is a non linear expression

It is supposed that I have to get a State Space Linear Model of this and another two equations, but I don't know why these non/linear terms appeared there

I also suppose that is correct to assign 0 to the first derivatives of the generalized coordinates, because It is a State of equilibrium and in the Taylor expansion form, you must evaluate the first derivatives in that point, but maybe I am wrong in this belief
 
Anyone knows the proper way to assign the initial conditions for the first order derivatives to the Series function??
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
Replies
7
Views
1K