Skip to main content

calculus and analysis - Multivariate series for approximating implicit system


I'm trying to approximate the solution of an implicit set of equations by means of a Taylor series. I have managed to do so for a solution expressed in terms of a single independent variable, by using the Dt function, solving for the required derivatives, and manually constructing the Taylor series (also for higher-order derivatives).


Now, the complexity (for me) increases:



  • I have three implicit equations and

  • would like to approximate the solution of three unknowns

  • in terms of two independent variables,

  • using up to the fourth derivatives.



For this problem size, I can probably still figure out the implicit differentiation and Taylor series by hand, but I would like Mathematica to help me with this, since I anticipate more complex problems in the future.




Edit: an example of the equations I am dealing with:


(*P defines a potential: *)
P = -M Rz + (360 (L^2 Rz^2 - 3 L Rz Uy + 3 Uy^2) + (2 L^2 Rz^2 +
30 L Ux - 3 L Rz Uy + 18 Uy^2)^2)/(180 L^3) - Ux V + (1/(
180 L^3))(1/
4 (L^2 (-12 + Rz (3 + 4 Rz)) + 6 L (6 + Rz) Ux + 36 Ux^2 +
60 L Uy - 3 L (L (-4 + Rz) + 12 Ux) Cos[Rz] -

3 L (L (16 + Rz) + 12 Ux - 6 L Cos[Rz]) Sin[Rz])^2 +
360 (L^2 Rz^2 + 3/2 L Rz (L + 2 Ux - L (Cos[Rz] + Sin[Rz])) +
3/4 (L + 2 Ux - L (Cos[Rz] + Sin[Rz]))^2));

(*The three equations are given by:*)
eqs = D[P==0,{{Ux,Uy,Rz},1}]

The two independent variables are Rz and V. The three dependent variables are Ux, Uy and M. Parameter L is a constant. I know that Ux=Uy=Rz=V=M=0 is a solution; this would be the point around which to expand the series, ideally up to fourth order and higher.




In particular, I'm struggling to obtain the various partial derivatives systematically by means of Dt and turn them into a multivariable Taylor series programmatically. I find the nested lists of Mathematica for higher dimensions hard to visualise.



How to solve for the required derivatives and turn them into a series, for this vector-valued multivariate case?



Answer



This gets pretty complicated if we work with the parameter so I'll show the main idea with l set to 1.


I am using uncapitalized symbols since that is recommended practice.


pExpr = -(m*
rz) + (360*(l^2*rz^2 - 3*l*rz*uy + 3*uy^2) + (2*l^2*rz^2 +
30*l*ux - 3*l*rz*uy + 18*uy^2)^2)/(180*l^3) -
ux*v + ((l^2*(-12 + rz*(3 + 4*rz)) + 6*l*(6 + rz)*ux + 36*ux^2 +
60*l*uy - 3*l*(l*(-4 + rz) + 12*ux)*Cos[rz] -
3*l*(l*(16 + rz) + 12*ux - 6*l*Cos[rz])*Sin[rz])^2/4 +

360*(l^2*rz^2 + (3*l*rz*(l + 2*ux - l*(Cos[rz] + Sin[rz])))/
2 + (3*(l + 2*ux - l*(Cos[rz] + Sin[rz]))^2)/4))/(180*
l^3) /. l -> 1;

Here are some relevant definitions.


derivVars = {ux, uy, rz};
solveVars = {ux, uy, m};
indepVars = {rz, v};

We define some substitutions, first to make explicit dependencies of dependent on independent variables.



subst = 
Thread[solveVars -> Map[Apply[#, indepVars] &, solveVars]]

(* Out[155]= {ux -> ux[rz, v], uy -> uy[rz, v], m -> m[rz, v]} *)

Then we use a "center" point for the expansions. I chose something away from the origin so as to get away from the initial values all being zero, but this seems not to be strictly necessary.


centerVal = {1, 1/2};
centerSubst = Thread[indepVars -> centerVal];

We start by taking derivatives with respect to the set of variables specified in the question. This gives three (nonlinear) equations in three unknowns.



derivs1 = D[pExpr, {derivVars, 1}];

We now plug in dependencies and solve at the center point for the variables of interest. I am doing this numerically so as to reduce size of results. I assume it is the real valued solution that is of interest so I select that one to work with.


solns0 = NSolve[(derivs1 /. subst /. centerSubst), 
solveVars /. subst /. centerSubst];
realsolns = SelectFirst[solns0, FreeQ[#, Complex] &]

(* Out[157]= {ux[1, 1/2] -> -0.226565925725,
uy[1, 1/2] -> 0.521293098575, m[1, 1/2] -> 2.47566148214} *)


Since we are on a level set, derivatives of the expressions must vanish. So from here on we do implicit differentiation with respect to the independent variables, solve for the new derivatives after back substituting values for lower derivatives. So we successively build up our solution set. This is easy enough since now all equations are linear.


derivs2 = Flatten[D[derivs1 /. subst, {indepVars, 1}]];
solns1 = NSolve[derivs2 /. centerSubst /. realsolns][[1]]
realsolns = Join[realsolns, solns1];

(* Out[117]= {Derivative[0, 1][m][1, 1/2] -> 0.5049474410685676,
Derivative[0, 1][ux][1, 1/2] -> 0.04247077151821635,
Derivative[0, 1][uy][1, 1/2] -> -0.0021891966235871533,
Derivative[1, 0][m][1, 1/2] -> 3.035009091874597,
Derivative[1, 0][ux][1, 1/2] -> -0.5049474410685676,

Derivative[1, 0][uy][1, 1/2] -> 0.527428429008325} *)

Rinse and repeat:


derivs3 = Flatten[D[derivs2, {indepVars, 1}]];
solns2 = NSolve[(derivs3 /. centerSubst /. realsolns) == 0][[1]]
realsolns = Join[realsolns, solns2];

(* Out[122]= {Derivative[0, 2][m][1, 1/2] -> 0.0058561848991389885,
Derivative[0, 2][ux][1, 1/2] -> 0.0012407744471675428,
Derivative[0, 2][uy][1, 1/2] -> -0.0008707825473032442,

Derivative[1, 1][m][1, 1/2] -> 0.4689741977236943,
Derivative[1, 1][ux][1, 1/2] -> -0.005856184899138995,
Derivative[1, 1][uy][1, 1/2] -> -0.0029987473716603917,
Derivative[2, 0][m][1, 1/2] -> 2.0658369667032397,
Derivative[2, 0][ux][1, 1/2] -> -0.4689741977236943,
Derivative[2, 0][uy][1, 1/2] -> -0.025714139536380225} *)

If it is really important to get the parametrized result, we can start at the origin and then things are not so terrible because the initial solution is simple (all zeros). I'll just show the main steps, using Solve now instead of the numeric version.


centerVal = {0, 0}; centerSubst = Thread[indepVars -> centerVal]; derivs1 = D[pExpr, {derivVars, 1}]; solns0 = Solve[(derivs1 /. subst /. centerSubst) == 0, solveVars /. subst /. centerSubst]; realsolns = SelectFirst[solns0 /. l -> 1., FreeQ[#, Complex] &]


(* Out[282]= {ux[0, 0] -> 0, uy[0, 0] -> 0, m[0, 0] -> 0} *)



derivs2 = D[derivs1 /. subst, {indepVars, 1}];
newexpr = (derivs2 /. centerSubst /. realsolns);
solns1 = Solve[newexpr == 0,
Complement[Variables[newexpr], {l}]][[1]]
realsolns = Join[realsolns, solns1];

(* Out[272]= {Derivative[0, 1][m][0, 0] -> 0,
Derivative[0, 1][ux][0, 0] ->
l^3/(2*(6 + 5*l^2)), Derivative[0, 1][uy][0, 0] -> 0,
Derivative[1, 0][m][0, 0] -> 2/l,

Derivative[1, 0][ux][0, 0] -> 0,
Derivative[1, 0][uy][0, 0] -> l/2} *)

derivs3 = Flatten[D[derivs2, {indepVars, 1}]];
newexpr = (derivs3 /. centerSubst /. realsolns);
solns2 = Solve[newexpr == 0,
Complement[Variables[newexpr], {l}]][[1]]
realsolns = Join[realsolns, solns2];

(* Out[298]= {Derivative[0, 2][m][0, 0] -> 0,

Derivative[0, 2][ux][0, 0] -> 0,
Derivative[0, 2][uy][0, 0] -> -((3*l^7)/(2*(6 + 5*l^2)^3)),
Derivative[1, 1][m][0, 0] -> -((-9*l - 5*l^3)/(3*(6 + 5*l^2))),
Derivative[1, 1][ux][0, 0] -> 0, Derivative[1, 1][uy][0, 0] -> 0,
Derivative[2, 0][m][0, 0] -> 0, Derivative[2, 0][ux][0, 0] ->
-((9*l + 5*l^3)/(3*(6 + 5*l^2))), Derivative[2, 0][uy][0, 0] ->
(5*l^3)/(6*(6 + 5*l^2))} *)

Continue as far as needed...


Comments

Popular posts from this blog

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

How to thread a list

I have data in format data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}} Tableform: I want to thread it to : tdata = {{{a1, b1}, {a2, b2}}, {{a1, c1}, {a2, c2}}, {{a1, d1}, {a2, d2}}} Tableform: And I would like to do better then pseudofunction[n_] := Transpose[{data2[[1]], data2[[n]]}]; SetAttributes[pseudofunction, Listable]; Range[2, 4] // pseudofunction Here is my benchmark data, where data3 is normal sample of real data. data3 = Drop[ExcelWorkBook[[Column1 ;; Column4]], None, 1]; data2 = {a #, b #, c #, d #} & /@ Range[1, 10^5]; data = RandomReal[{0, 1}, {10^6, 4}]; Here is my benchmark code kptnw[list_] := Transpose[{Table[First@#, {Length@# - 1}], Rest@#}, {3, 1, 2}] &@list kptnw2[list_] := Transpose[{ConstantArray[First@#, Length@# - 1], Rest@#}, {3, 1, 2}] &@list OleksandrR[list_] := Flatten[Outer[List, List@First[list], Rest[list], 1], {{2}, {1, 4}}] paradox2[list_] := Partition[Riffle[list[[1]], #], 2] & /@ Drop[list, 1] RM[list_] := FoldList[Transpose[{First@li...

front end - keyboard shortcut to invoke Insert new matrix

I frequently need to type in some matrices, and the menu command Insert > Table/Matrix > New... allows matrices with lines drawn between columns and rows, which is very helpful. I would like to make a keyboard shortcut for it, but cannot find the relevant frontend token command (4209405) for it. Since the FullForm[] and InputForm[] of matrices with lines drawn between rows and columns is the same as those without lines, it's hard to do this via 3rd party system-wide text expanders (e.g. autohotkey or atext on mac). How does one assign a keyboard shortcut for the menu item Insert > Table/Matrix > New... , preferably using only mathematica? Thanks! Answer In the MenuSetup.tr (for linux located in the $InstallationDirectory/SystemFiles/FrontEnd/TextResources/X/ directory), I changed the line MenuItem["&New...", "CreateGridBoxDialog"] to read MenuItem["&New...", "CreateGridBoxDialog", MenuKey["m", Modifiers-...