RE: Symbolic Derivatives of Unspecified Functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg70675] RE: [mg70665] Symbolic Derivatives of Unspecified Functions*From*: "David Park" <djmp at earthlink.net>*Date*: Mon, 23 Oct 2006 02:49:41 -0400 (EDT)

Misha, I'm not certain if I'm following everything you are asking, but I think the following might help. You want to use the Derivative statement. So in the following I define a derivative operator that is the derivative of an unspecifed function with respect to the first argument plus the derivative with respect to the second argument. op1 := Derivative[1, 0][f] + Derivative[0, 1][f] We can then apply this to a set of arguments and then use the Through command to push the arguments onto the Derivative commands and then finally specify a specific function for f. op1[g1, h1] % // Through % /. f -> Function[{x, y}, x^2 + y] (Derivative[0, 1][f] + Derivative[1, 0][f])[g1, h1] Derivative[0, 1][f][g1, h1] + Derivative[1, 0][f][ g1, h1] 1 + 2 g1 But a problem arises with the Through command if we try to define a more general derivative operator. op2 := a Derivative[1, 0][f] - b Derivative[0, 1][f] op2[g1, h1] % // Through % /. f -> Function[{x, y}, x^2 + y] ((-b)*Derivative[0, 1][f] + a*Derivative[1, 0][f])[g1, h1] ((-b)*Derivative[0, 1][f])[g1, h1] + (a*Derivative[1, 0][f])[g1, h1] (-b Function[{x, y}, 1])[g1, h1] + (a Function[{x, y}, 2 x])[g1, h1] The arguments do not get pushed onto the Derivative[..][f] commands. And if you try to do another Through it gets even more messed up. The free Algebra`PushThrough` package from my web site has a convenient solution to this. It contains a command PushOnto that will push the arguments onto specific forms and not onto anything else. Needs["Algebra`PushThrough`"] op2[g1, h1] % // PushOnto[{Derivative[__][_]}] % /. f -> Function[{x, y}, x^2 + y] ((-b)*Derivative[0, 1][f] + a*Derivative[1, 0][f])[g1, h1] (-b)*Derivative[0, 1][f][g1, h1] + a*Derivative[1, 0][f][g1, h1] -b + 2*a*g1 I hope that helps some. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: misha [mailto:iamisha1 at comcast.net] To: mathgroup at smc.vnet.net My apologies for the long post. A brief form of the question is the first sentence of the next paragraph. I'm a very inexperienced Mathematica user and am probably expecting too much and/or being too lazy, but I was wondering whether Mathematica can do something I describe below, and, if so, how to implement it. I also apologize for my likely misuse of notation, terminology, etc. I think my question boils down to whether I can use Mathematica to take derivatives of functions that have no functional form. It seems like this is possible, given an example I found in the help files. D[f[g[x]],x]=f'[g[x]]g'[x] For example, as a first shot, I tried, In[1]:= r[qi_, qj_]=r[qi,qj] $ IterationLimit::itlim : Iteration limit of 4096 exceeded. More... Out[1]:= Hold[r[qi,qj]] In[2]:= qi[gi_, gj_]=qi[gi,gj] $ IterationLimit::itlim : Iteration limit of 4096 exceeded. More... Out[2]:= Hold[qi[gi,gj]] In[3]:= qj[gi_, gj_]=qj[gi,gj] $ IterationLimit::itlim : Iteration limit of 4096 exceeded. More... Out[3]:= Hold[qj[gi,gj]] In[4]:= D[r[qi[gi,gj],qj[gi,gj]],gi] $ IterationLimit::itlim : Iteration limit of 4096 exceeded. More... $ IterationLimit::itlim : Iteration limit of 4096 exceeded. More... $ IterationLimit::itlim : Iteration limit of 4096 exceeded. More... General::stop: Further output of $IterationLimit::itlim will be suppressed during this calculation. More... Out[4]:= D[Hold[r[Hold[qi[gi,gj]], Hold[qj[gi,gj]]]],gi] I would like something like, r_1*d{qi}/d{gi} + r_2*d{qj}/d{gi}, where r_1 is the partial derivative of r w.r.t. its first argument, r_2 is the partial derivative of r w.r.t. its second argument. So, say I have some functions that assume little or no specific functional form. Di=[(beta*(gi+gj))/(1-theta)][gi/(gi+gj) + theta*gj/(gi+gj)] alpha=beta/(1-theta) (obviously this is specific) Ci(Gi)=ci(Gi)*qi, (ci(Gi) has no specific form) Gi(gi, gj, beta, theta) = (1 - alpha)*gi + alpha*theta*gj pi_i(gi,gj,qi,qj,beta,theta)=ri(qi,qj)-ci(Gi)*qi-(v*gi^2)/2, where ri and ci do not have functional forms. (I'd also like to work with a less specific form of (v*gi^2)/2, but I'll set that aside for now...). I want to take derivatives, such as derivative of pi_i with respect to qi, a first order condition, or FOC (1) d{pi_i}/d{qi} = 0 then the derivative of (1) w.r.t. qi and qj, and the total derivative of (1) w.r.t gi, assuming qi and qj are functions of gi (and gj). I get some results that include expressions with "Hold" and problems with iterations. Here are more details about the above problems and what I want Mathematica to do... This may be obvious, but this is a two-stage oligopoly model with investment. With specific functional forms one can do something like the following: Solving the second (i.e., last) stage of the game in Cournot competition (i.e., firms i and j maximize profit, pi_i, pi_j, choosing qi and qj, respectively) will yield expressions for qi and qj in terms of the other variables, gi, gj, beta, and theta. This is done by setting the first derivative of pi_i w.r.t. qi equal to zero, then solving for qi. Then, using these expressions, you move to the first stage and solve for the optimal investments, gi and gj, by substituting the above qi and qj into pi_i, setting the first derivative of pi_i w.r.t. gi to zero, and solving for gi, yielding expression in terms of beta and theta. However, without assuming functional forms, it gets a little hairier...making a number of common assumptions, such as d{ri}/d{qj}<0, d{ri}/(d{qi}d{qj})<0, d{ci}/d{G}<0, d^2{ci}/d{G^2} >0, symmetry (d{ri}/(d{qi}d{qj}) = d{rj}/(d{qj}d{qi}) = r_ij, d^2{ri}/d{qi^2} = d^2{rj}/{qj^2} = r_ii, and some others, gets a FOC that looks something like (2) d{pi_i}/d{qi}=d{ri}/d{qi}-d{ci}/d{qi} = 0 Then, since there's no functional form, one obviously cannot solve for qi, so the goal is to find the slope of the "reaction function", d{qj}/d{qi}, which turns out to be (in this model) (3) d{qj}/d{qi}=-(d^2{ri}/d{qi^2})/(d^2{ri}/d{qi}d{qj}). This comes from totally differentiating (2) w.r.t. qi and qj. Then, one can solve the the changes in qi and qj w.r.t. changes in gi, d{qi}/d{gi} and d{qj}/d{gi}, by totally differentiating (2) and its equivalent for pi_j w.r.t. gi. There is far more than this, but if I can get this done in Mathematica, my life will be far easier. Ideally, I can get "nice" expressions that can be exported into a TeX file via Mathematica. Many thanks in advance for reading and responding. Misha

**Re: Symbolic Derivatives of Unspecified Functions**

**Re: Using "=" vs ":="**

**Re: Symbolic Derivatives of Unspecified Functions**

**Re: Symbolic Derivatives of Unspecified Functions**