Re: Numerical Differentiation in C

From: Paul (unthrall_at_rmci.net)
Date: 09/26/04


Date: Sun, 26 Sep 2004 10:47:05 -0700

Carl Devore wrote:

> On Fri, 24 Sep 2004, Paul wrote:
>
>>I'm writing a routine to calculate the n'th derivative of a function
>>numerically. I took the standard difference equation from calculus and
>>wrote it out in C++.
>>
>>float diff(float(*f)(float), float x, float n, float h)
>> //The difference equation from calc 1
>> df = (diff(f,x+h, n - 1, h) - diff(f,x, n - 1, h)) / h;
>> df = (f(x+h) - f(x)) / h;
>
>
> Peter Spellucci did cover the following point, but I want to emphasize
> that it is one simple thing that will drastically improve the performance
> of your program: Use
> df = (f(x+h) - f(x-h))/(2*h)
> as the difference equation. Look at it on a graph: The slope of a secant
> line that goes on either side of the point at which you want the
> derivative is usually much closer to the slope of the tangent line than is
> the slope of a secant line that goes through the point at which you want
> the derivative.
Hmmmm, good point.
>
> Also, minor point: Why use a float instead of an int for n?
>
*shrug*
Cause.

-paul



Relevant Pages

  • Re: Numerical Differentiation in C
    ... > float diff, float x, float n, float h) ... as the difference equation. ... Look at it on a graph: The slope of a secant ...
    (sci.math.num-analysis)
  • Re: Fundamental Theorem of Calculus
    ... we are trying to find the slope of the tangent at the ... point ) as an approximation of the slopes of secant lines: ... Both "definitions" yield the exact same answer, ... --- Calvin ...
    (sci.math)
  • Re: what "REALLY" is derivative?
    ... Or if you divide Fby (x-a) remainder is zero. ... > and that is the slope of a line touching parabola at x = q. ... This is the slope of the secant cutting the parabola at two ...
    (sci.math)
  • Re: Fundamental Theorem of Calculus
    ... This "natural" way uses the secant line in the increasing direction ... My definition uses the hypotenuse as the slope instead of the vertical leg. ...
    (sci.math)
  • Re: derivative problem correctness check
    ... The graph of flies between the two parabolas ... Because of this, any secant line joining to ... and note that the secant's slope must approach 0. ...
    (sci.math)

Quantcast