Re: Partial derviatives in mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg95790] Re: Partial derviatives in mathematica
- From: dh <dh at metrohm.com>
- Date: Tue, 27 Jan 2009 06:59:54 -0500 (EST)
- References: <glk1na$los$1@smc.vnet.net>
Hi,
I would write input in InputForm not TraditionalForm. A derivative is
then written:
D[f[x],x]
If you later need TraditionalForm, you can get it by wrapping an
expression in TraditionalForm[..]. Or reformatting the whole cell.
Your problem comes from the fact that PartialD needs a subscript,
indicating the variable to differentiate after.
hope this helps, Daniel
xareon at gmail.com wrote:
> Hi all, i got thi Newton-Raphson mathematica code:
>
>
>
> Code:
>
> F[{x_, y_}] = {f1[{x, y}], f2[{x, y}]};
>
> jacobian[{x_, y_}] = Transpose[{\[PartialD]x F[{x, y}], \[PartialD]y F
> [{x, y}]}];
>
> MatrixForm[jacobian[{x, y}]];
>
> NewtonSystem[X0_, max_] := Module[{},
> n = 2;
> k = 0;
> Dp = {0, 0};
> P0 = X0;
> F0 = F[P0];
> Print["F[", P0, "]=", N[F0, 3]];
> P1 = P0;
> F1 = F0;
> While[k < max,
> k = k + 1;
> P0 = P1;
> F0 = F1;
> J0 = jacobian[P0];
> det = Det[J0];
> If[det == 0, Dp = {0, 0}, Dp = Inverse[J0].F0];
> P1 = P0 - Dp;
> F1 = F[P1];
> Print["F[", P1, "]=", N[F1, 3]];];];
>
>
>
> where f1[x, y] and f2[x, y] are defined in this way
>
>
>
> Code:
>
> f1[{x_, y_}] = n/x - Sum[y*Exp[-y*A*t[i]]*T[i+1], {i, 0, n-1}];
>
> f2[{x_, y_}] = n/y - Sum[A*t[i], {i, 0, n-1}] - Sum[x*Exp[-y*A*t[i]]*T
> [i+1], {i, 0, n-1}] + Sum[y*x*A*t[i]*Exp[-y*A*t[i]]*T[i+1], {i, 0,
> n-1}];
>
>
>
>
> T[i] e t[i] are functions defined point-by-point (from T[1] to T[50]
> and from t[0] to t[49]) with this syntax:
>
>
> Code:
>
> t[0] = *un certo numero*; t[1] = *un altro numero*; t[2] = *ancora un
> altro numero*; ... T[1] = *numero*; T[2] = *altro numero* ...
>
>
>
> I got an error on the second line
>
>
>
> Code:
>
> jacobian[{x_, y_}] = Transpose[{\[PartialD]x F[{x, y}], \[PartialD]y F
> [{x, y}]}];
>
>
>
> Mathematica's kernel warns me with this message when i try to insert
> it:
>
>
> Code:
>
> Syntax::sntxf: "jacobian[{x_, y_}] = Transpose[{" cannot be followed
> by
> "\[PartialD]x F[{x, y}], \[PartialD]y F[{x, y}]}];".
>
>
>
>
> This line should define a 2-variables function named jacobian, that is
> a jacobian matrix. I'm not a Mathematica-guru, but the code should
> work anyway.
>
> What's wrong there? f1 and f2 seem well defined (i.e., when i write
> them Mathematica doesn't say nothing bad):
>
>
>
> Thank you all ;)
>