MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Derivative Evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6060] Re: [mg6017] Derivative Evaluation
  • From: go.gators at pobox.com
  • Date: Sun, 16 Feb 1997 01:12:02 -0500
  • Organization: MindSpring Enterprises
  • Sender: owner-wri-mathgroup at wolfram.com

John Cigana <giotto at step.polymtl.ca> wrote:

>Hello, 

>I have a 7 parameters multivariate function. i.e. y = f(x1..x7).

>I am able to correctly find the partial derivative for each parameter.

>However, I can't seem to be able to evaluate my derivative at a given
>point. i.e. f'(x1=0.01, x2=0.5, x3=0.02, ... x7=0.05) = Value !

>Any insight on the subject ?? Any help appreciated !

>Thanks,

>JOHN CIGANA,

Hi John.  Sorry about the blank reply (If it got posted) I had to
configure my newsreader. I had this same question when I first started
using MMA.  Here's the best I can do by way of an answer.

First Clear[] and symbol definitions you've made in the current
context using Clear[y,yVars,yVarRules,x1,x2,x3,x4,x5,x6,x7,partials].
You don't need to do this if you start a new session.

In[1]:=
 Clear[y,yVars,yVarRules,x1,x2,x3,x4,x5,x6,x7,partials]

Here is a function that takes partials of a function with respect to
each variable in vars.

In[2]:=
partials[fnc_,vars_]:=Map[D[fnc, #] &,vars]
Now define  your function y=f(x1,...,x7)

In[3]:=
y=(x1*x2^2+x3^3*x4)*x5*x6^2*x7

Out[3]=
\!\(\((x1\ x2\^2 + x3\^3\ x4)\)\ x5\ x6\^2\ x7\)

Now define a list of the variables in y.
In[4]:=
yVars={x1,x2,x3,x4,x5,x6,x7}

Out[4]=
{x1,x2,x3,x4,x5,x6,x7}
Now define some replacement rules for the variables.  I think this is
all you really need to know but I thought the function definition for
partials[] might be useful and/or give you some things to think
about.I took me a long time to realize the usefullness of replacement
rules.  Play with them, read about them in the BOOK, and you will
learn to love them.   They allow you to replace symbols with other
things while keeping the symbols undefined.  i.e., you can
 continue doing algebraic operations on y even after checking the
numerical value with the replacement rules.  Also, you can define a
replacement rule of the form x1->Sqrt[x]  or x2->somestuff, play with
them and all will become clear.

In[5]:=
yVarRules={x1->1,x2->2,x3->3,x4->4,x5->5,x6->6,x7->7}

Out[5]=
{x1\[Rule]1,x2\[Rule]2,x3\[Rule]3,x4\[Rule]4,x5\[Rule]5,x6\[Rule]6,x7\[Rule]7}
  
Now evaluate partials[y,yVars] and you get the symbolic result.

In[6]:=
partials[y,yVars]

Out[6]=
\!\({x2\^2\ x5\ x6\^2\ x7, 2\ x1\ x2\ x5\ x6\^2\ x7, 
    3\ x3\^2\ x4\ x5\ x6\^2\ x7, x3\^3\ x5\ x6\^2\ x7, 
    \((x1\ x2\^2 + x3\^3\ x4)\)\ x6\^2\ x7, 
    2\ \((x1\ x2\^2 + x3\^3\ x4)\)\ x5\ x6\ x7, 
    \((x1\ x2\^2 + x3\^3\ x4)\)\ x5\ x6\^2}\)

Now evaluate partials[y,yVars]/.yVarRules to get a numerical result.

In[7]:=
partials[y,yVars]/.yVarRules

Out[7]=
{5040,5040,136080,34020,28224,47040,20160}

The "/."  operator applies replacement rules.  Read about it, learn
it, and you will wonder how you ever lived without it.  
Here is the example so you can cut and past it into a nootbook.  In
this example, I use the % operator to refer to the previous output
line.  i.e.,  %/.yVarRules simiply means take the last output, %, and
apply /.yVarRules to it.  I hope this is not too confusing but the
info I've presented here is really important (I think anyway) so work
at understanding it!  It will payoff!!!
=======================Cut below==================
Clear[y,yVars,yVarRules,x1,x2,x3,x4,x5,x6,x7,partials]
partials[fnc_,vars_]:=Map[D[fnc, #] &,vars]
y=(x1*x2^2+x3^3*x4)*x5*x6^2*x7
yVars={x1,x2,x3,x4,x5,x6,x7}
yVarRules={x1->1,x2->2,x3->3,x4->4,x5->5,x6->6,x7->7}
partials[y,yVars]
%/.yVarRules
======================Cut above==================

Hope this was more helpfull than confusing!
	Justin



  • Prev by Date: Re: System of Equations
  • Next by Date: HELP!!!
  • Previous by thread: Re: Derivative Evaluation
  • Next by thread: Formatting Text