[Date Index]
[Thread Index]
[Author Index]
Re: Symbolic Derivatives of Unspecified Functions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg70693] Re: Symbolic Derivatives of Unspecified Functions
*From*: David Bailey <dave at Remove_Thisdbailey.co.uk>
*Date*: Mon, 23 Oct 2006 02:50:52 -0400 (EDT)
*References*: <ehf1mp$5e9$1@smc.vnet.net>
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
Prev by Date:
**Re: Re: Programming style: postfix/prefix vs. functional**
Next by Date:
**RE: Symbolic Derivatives of Unspecified Functions**
Previous by thread:
**Symbolic Derivatives of Unspecified Functions**
Next by thread:
**RE: Symbolic Derivatives of Unspecified Functions**
| |