|
[Date Index]
[Thread Index]
[Author Index]
Compiled function
- To: mathgroup at smc.vnet.net
- Subject: [mg93776] Compiled function
- From: SigmundV <sigmundv at gmail.com>
- Date: Tue, 25 Nov 2008 07:19:23 -0500 (EST)
Dear group,
Consider the following:
derData[data_, h_] := (Drop[data, 1] - Drop[data, -1])/h;
front = With[
{fa =
Function[{x, y}, Piecewise[{{0, 2 <= x <= 3 && 2 <= y <= 3}}, 1],
Listable],
fc = Function[{x, y}, (x y + 10)^0]},
Compile[{{r, _Real, 2}, {dt, _Real}, {\[Theta], _Real}},
Module[{x, y, a, b, c, C = Cos[\[Theta]], S = Sin[\[Theta]], da,
db, dc, dx, dy, cxy, xy, cxyxy, xnew, ynew,
dphi = 2 \[Pi]/1000},
x = r[[All, 1]]; y = r[[All, 2]];
dx = derData[x, dphi]; dx = Join[dx, {dx[[1]]}];
dy = derData[y, dphi]; dy = Join[dy, {dy[[1]]}];
a = fa[x, y];
b = 2 a; c = fc[x, y];
da = derData[a, dphi]; da = Join[da, {da[[1]]}]; db = 2 da;
dc = derData[c, dphi]; dc = Join[dc, {dc[[1]]}];
cxy = dc dt + S dx + C dy; xy = C dx - S dy;
cxyxy = a^2 cxy^2 + b^2 xy^2;
xnew =
x + dt c S + dt^2 (-a^2 b db (dc dt S + dx))/cxyxy +
dt (a^2 C cxy - b^2 S xy) Sqrt[cxyxy - a^2 db^2 dt^2]/cxyxy;
ynew =
y + dt c C + dt^2 (-a^2 b db (dc dt C + dy))/cxyxy -
dt (a^2 S cxy + b^2 C xy) Sqrt[cxyxy - a^2 db^2 dt^2]/cxyxy;
Transpose[{xnew, ynew}]
]
]
];
As you see, fa is a piecewise function, but the module won't compile.
However, when fa is a continuous function, like Exp[-(x^2 + y^2)], the
module compiles without problems. Can anyone shed some light on this?
Why does the compilation work in the latter case, but not in the
first?
King regards,
Sigmund Vestergaard
Prev by Date:
Re: Primed Symbols in Mathematica
Next by Date:
Solve and parametric nonlinear equations
Previous by thread:
Re: Using Alt or Cmd Keys to Enter Cell Types
Next by thread:
Re: Compiled function
|