Re: Symbolic Derivatives of Unspecified Functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg70718] Re: Symbolic Derivatives of Unspecified Functions*From*: misha <iamisha1 at comcast.net>*Date*: Tue, 24 Oct 2006 02:24:30 -0400 (EDT)*References*: <ehf1mp$5e9$1@smc.vnet.net> <ehhqlj$7cm$1@smc.vnet.net>

As suggested, I tried In[1]:=r[qi_, qj_]=r[qi,qj] as opposed to In[1]:=r[qi_, qj_]:=r[qi,qj] ....but I still get an error message, $IterationLimit::itlim : Iteration limit of 4096 exceeded. More... Out[1]:=Hold[ri[qi,qj]] I subsequently take a derivative (ignoring the error message, contrary to advice sent to me regardin this) after entering a few other functions and getting similar error messages in the case of unspecified functions (e.g., ci[Gi_]=ci[gi]). .... In[n]:= profiti[qi_,qj_,beta_,theta_,gi_,gj_]=r[qi, qj] - ci[Gi]*qi-v*gi^2/2 $IterationLimit::itlim : Iteration limit of 4096 exceeded. More... $IterationLimit::itlim : Iteration limit of 4096 exceeded. More... Out[n]:=-(gi^2)*v/2 - qi Hold[ci[Gi]] + Hold[ri[qi,qj]] In[n+1]:= D[profiti[qi,qj,beta,theta,gi,gj],qi] Out[n+1]:=del_{qi}Hold[ri[qi,qj]]-Hold[ci[Gi]] Which is , in terms of correctness, what I want. But I still have many questions... 1) What does the "$IterationLimit" error message mean and why doesn't using "=" as opposed to ":=" resolve this (as interpreted the reply below to suggest)? I read the Help Browser after clicking on "More...", but that doesn't really clarify things for me in this context. I "just" want to have ri be a function of qi and qj so that when I take derivatives of functions that include ri (say w.r.t. qi), I will get something like D[ri[qi,qj], qi], or, ideally, something that I can easily render into a TeX file. Thanks! Misha David Bailey wrote: > misha wrote: > >>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 >> >> > > Hello, > > As you point out at the start, it is possible to take derivatives of > expressions that contain undefined functions - but in that case, don't > try to define them! > > r[qi_, qj_]=r[qi,qj] > > You do not want a definition for r, and this definition is infinitely > recursive (which is why you get an error message). As a general point, > there is no point in ignoring an error like that - you have to discover > why it is happening! > > If later, you want the function r to have a specific form, don't use a > function definition, just use a replacement rule, for example: > > r[a,b]^2 /. r[x_,y_]->Exp[(x+y)^2] > > Manipulating expressions with replacement rules is often much more > convenient than doing everything with definitions, because you can use a > replacement rule when and where you want it. > > I hope this gives you a start at least. > > David Bailey > http://www.dbaileyconsultancy.co.uk >

**Re: Re: Re: Programming style: postfix/prefix vs. functional**

**what's the command to load a specific "page" in the help browser?**

**RE: Symbolic Derivatives of Unspecified Functions**

**Re: Symbolic Derivatives of Unspecified Functions**