RE: Variable functions
- To: mathgroup at smc.vnet.net
- Subject: [mg36228] RE: [mg36180] Variable functions
- From: "David Park" <djmp at earthlink.net>
- Date: Tue, 27 Aug 2002 02:07:42 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Raj, You could include an index for the function in the argument list, or make a clear separation between "parameters" and "variables" as follows (I just use two functions). f[1][r_, t_, p_] := 2r Sin[t] f[2][r_, t_, p_] := r Cos[t]Sin[p] You could then sum them, for example, by Sum[f[i][r, t, p], {i, 1, 2}] r Cos[t] Sin[p] + 2 r Sin[t] Or perhaps you wish to sum the derivatives of the functions with respect to the second argument, t. Sum[Derivative[0, 1, 0][f[i]][r, t, p], {i, 1, 2}] 2 r Cos[t] - r Sin[p] Sin[t] Perhaps you can define all your functions in terms of integer parameters. g[n_, m_][r_, t_, p_] := r^(m - n)Sin[m t]Cos[n p] You could then sum as follows. Sum[g[n, m][r, t, p], {m, 1, 3}, {n, 1, 3}] Cos[p]*Sin[t] + (Cos[2*p]*Sin[t])/r + (Cos[3*p]*Sin[t])/r^2 + r*Cos[p]*Sin[2*t] + Cos[2*p]*Sin[2*t] + (Cos[3*p]*Sin[2*t])/r + r^2*Cos[p]*Sin[3*t] + r*Cos[2*p]*Sin[3*t] + Cos[3*p]*Sin[3*t] Or perhaps you want to take the square of the derivatives of the functions with respect to the first argument, r... Sum[(Derivative[1, 0, 0][g[n, m]][r, t, p])^2, {m, 1, 3}, {n, 1, 3}] (Cos[2*p]^2*Sin[t]^2)/r^4 + (4*Cos[3*p]^2*Sin[t]^2)/ r^6 + Cos[p]^2*Sin[2*t]^2 + (Cos[3*p]^2*Sin[2*t]^2)/ r^4 + 4*r^2*Cos[p]^2*Sin[3*t]^2 + Cos[2*p]^2*Sin[3*t]^2 If possible, try to steer away from For and Do loops and use functional programming as much as you can. At first it may seem strange, but it is much more powerful and easier once you get used to it. Ask further questions to MathGroup with SPECIFIC examples and you will get a lot of help on how to use functional programming. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Raj [mailto:rajgupta121 at rediffmail.com] To: mathgroup at smc.vnet.net Hi All, I am a newbie to mathematica. I have a 14 functions which are the function of r,theta and phi. I want to do some mathematical operation over them. How can I do? Can it be possible to call them in Do or For loop with some index? Please suggest. Raj