Re: How to parametrize a block of commands?
- To: mathgroup at smc.vnet.net
- Subject: [mg111047] Re: How to parametrize a block of commands?
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Sun, 18 Jul 2010 01:04:36 -0400 (EDT)
Hi, Here is a simpler working example to illustrate one possibility: In[1]:= Clear[makeDefs]; makeDefs[p_, q_] := Module[{}, Clear[f, g, h]; f[x_, y_] := Sin[p[x]*q[y]]; g[x_, y_] := Cos[p[x]/q[y]]; h[x_, y_] := f[x, y] + g[x, y];] In[3]:= makeDefs[Sin, Cos] In[4]:= h[a, b] Out[4]= Cos[Sec[b] Sin[a]] + Sin[Cos[b] Sin[a]] In[5]:= makeDefs[#^2 &, #^3 &] In[6]:= h[a, b] Out[6]= Cos[a^2/b^3] + Sin[a^2 b^3] Alternatively, you can pass functions as extra explicit parameters to those functions that use them. When you provide some sample code, I recommend to try constructing the simplest example illustrating your problem, and make sure it does work. Also, using capital letters as starting letters for your function or variable names is a bad habit. Hope this helps. Regards, Leonid On Sat, Jul 17, 2010 at 4:16 PM, Sam Takoy <sam.takoy at yahoo.com> wrote: > Hi, > > Suppose I have written the following block of commands for computing the > differential geometry elements on a surface of evolution given by r=F[g] > z=Z[g]. This topic not my interest, I just cooked it up for an example. > > TF[m_] := Flatten[Transpose[m]] > Combine[m1_, m2_] := > Partition[Join[m1 // TF, m2 // TF], Length[m1]] // T > R[g_, theta_] := {F[g] Cos[theta], F[g] Sin[theta], Z[g]} > Z1[g_, theta_] := Derivative[1, 0][R][g, theta] > Z2[g_, theta_] := Derivative[0, 1][R][g, theta] > UnitN[g_, theta_] := Cross[Z1[g, theta], Z2[g, theta]] // Normalize > shift[g_, theta_] := Combine[{Z1[g, theta]} // T, {Z2[g, theta]} // T] > m[g_, theta_] := Transpose[shift[g, theta]].shift[g, theta] > M[g_, theta_] := Inverse[m[g, theta]] > > M[g, theta] // MatrixForm > > > My question is this: could this entire block be turned into a function > "paramtrized" by F and Z. For example, denote that whole block by XXXXX. > Is there something along the lines of > > DiffGeom[F_, Z_] := XXXXX > r[g_] := a Cosh[(g - H/2)/a] > z[g_] := g > DiffGeom[r, z] > > In other words, once I have taught Mathematica to compute these objects > for general surfaces of revolution, I want it to apply it to a > particular surface of revolution. What's the best way to organize this? >