At the moment I have implemented the code for a Taylor 2nd order series for the function in three variables:
$x_3^3+\frac{x_1-x_2}{x_1+x_2}$
The code builds on following expression:
ClearAll["Global`*"]
Remove["Global`*"]
thetacalc[xtem_, utem_, nn_] := {
n = nn;
xx = Table[Subscript[x, i], {i, 1, n}];
uu = Table[Subscript[u, i], {i, 1, n}];
f1[x_] := ((x[[1]] - x[[2]])/(x[[1]] + x[[2]])) + (x[[3]])^3;
hh = Simplify[D[f1[xx + θ*uu], {xx, 2}]] // MatrixForm;
f2[f_, x_, u_] :=
f + Sum[uu[[j]]*D[f, {xx[[j]]}], {j, 1, n}] +
1/2*Sum[Sum[uu[[i]]*uu[[j]]*hh[[1, i, j]], {j, 1, n}], {i, 1, n}];
sol2 = FullSimplify[f2[f1[xx], xx, uu]];
uu = utem;
xx = xtem;
subst =
Flatten[{Table[Subscript[x, i] -> xx[[i]], {i, 1, n}],
Table[Subscript[u, i] -> uu[[i]], {i, 1, n}]}];
subst2 = Flatten[{Table[Subscript[x, i] -> xx[[i]], {i, 1, n}]}];
diff = f1[xx + uu] - sol2 /. subst;
{sei = NSolve[diff == 0, θ, Reals], diff, FullSimplify[hh] /. subst2, sein = FullSimplify[hh] /. Flatten[{subst, sei}], Eigenvalues[sein[[1]]]}
}
thetacalc[{10, 5, 1}, {1, 0, 0}, 3]
The output (theta, difference-function, H-Matrix [unevaluated], [evaluated], Eigenvalues) for x and u as given in thetacalc:
$\tiny \begin{array}{ccccc} \{\{\theta \to 0.326189\}\} & \frac{10}{(\theta +15)^3}-\frac{1}{360} & \left( \begin{array}{ccc} -\frac{4 \left(\theta u_2+5\right)}{\left(\theta \left(u_1+u_2\right)+15\right){}^3} & \frac{2 \left(\theta u_1-\theta u_2+5\right)}{\left(\theta \left(u_1+u_2\right)+15\right){}^3} & 0 \\ \frac{2 \left(\theta u_1-\theta u_2+5\right)}{\left(\theta \left(u_1+u_2\right)+15\right){}^3} & \frac{4 \left(\theta u_1+10\right)}{\left(\theta \left(u_1+u_2\right)+15\right){}^3} & 0 \\ 0 & 0 & 6 \left(\theta u_3+1\right) \\ \end{array} \right) & \left( \begin{array}{ccc} -0.00555556 & 0.00295899 & 0 \\ 0.00295899 & 0.0114735 & 0 \\ 0 & 0 & 6. \\ \end{array} \right) & \{6.,0.011973,-0.00605506\} \\ \end{array}$
The remainder will be adjusted with a theta between (0,1) from the mean value theorem to equal the original function (at point x with direction vector). A theta is given if the direction vector u is unequal to null-vector.
I am wondering if one could do this simpler as to avoid manual term calculation like the Hesse-matrix (in my code: hh) or even multiple sums.
Thank you for your time.
Subscript
for variables, when you doSubscript[x, i]=1
you are actually sayingSet
a downvalue toSubscript
not tox
. $\endgroup$