Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Derivatives of numerical functions : how does mathematica work?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61445] Derivatives of numerical functions : how does mathematica work?
  • From: amitgandhi at gmail.com
  • Date: Wed, 19 Oct 2005 02:16:44 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I have stumbled upon a seemingly basic problem - but my inability to
understand why I cannot get mathematica to work in the way I think it
should makes me question how well I understand the foundtaions of
mathematica.

Essentially I have a functions f[x] which takes x, and forms a system
of equations in the variables y1,...,yn where x appears as a parameter
to the system, and it uses FindRoot to solve for y1,...,yn and then
outputs the sum y1+...,yn. I know the solutions for y1,...,yn are
"smooth" in the parameter x, and thus I was interested  in finding the
numerical derivative of y1+...+yn with respect to the parameter x.
However I cannot get mathematica to implement this - I can illustrate
the difficulty in a very basic setting (excuse the fact that I can do
this "toy" problem analytically, because my real problem requires
numerics).

Suppose we have the equation

equ=x+y

For a particular value of x, I can solve the equation x+y=0 for y,
which for x=2.0 I do in mathematica as follows:

y /. FindRoot[x + y /. {x -> 2.0}, {y, 0}]


which yields the obvious -2.

Now I want to consider the above mathematica expression, which solves
for the value of y for a given x, as an expression that is variable in
x, and I wish to cconsider how the value of this expression varies with
x, i.e., the numerical derivative with respect to x. My inutuition for
mathematica suggests that I should write this as

<<NumericalMath`NLimit`
ND[y /. FindRoot[(x + y) /. {x -> c}, {y, 0}], c, 2.0]

However the output from entering this expression is a number of error
messages that read, the most important and telling one being that :

"The function value {0. + c} is not a list of numbers with \
dimensions {1} at {y} = {0.`}."

Why is this happening - doesn't ND try to replace c with a trial value
in the expression in the first argument of ND before it tries
evaluating the expression?

However after the error messages finish, the ND command manages to
produce the right answer, namely -1.

ND is just an example of this phenomena - the same thing would have
happened had I tried to use NLimit, FindMinumum, FindRoot, or a host of
other mathematica functions with the expression I defined above. Can
anyone explain how to get mathematica to work "error free" for a
problem like this, and whether the numerical answer that mathematica
produces should be trusted after producing a long list of errors.


Thanks
Amit


  • Prev by Date: Re: TagSet and the listability of Plus[ ]
  • Next by Date: Re: Double integral of a piecewise-constant function
  • Previous by thread: Re: Memory use by NMaximize (and NMinimize)
  • Next by thread: Re: Derivatives of numerical functions : how does mathematica work?