Re: Numerical Differentiation in C
From: Paul (unthrall_at_rmci.net)
Date: 09/26/04
- Next message: Paul: "Re: Numerical Differentiation in C"
- Previous message: Bob Ehrlich: "Re: Multiple Regression w/ Polynomial-in-Y?"
- In reply to: Carl Devore: "Re: Numerical Differentiation in C"
- Next in thread: r5: "Re: Numerical Differentiation in C"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Paul: "Re: Numerical Differentiation in C"
- Previous message: Bob Ehrlich: "Re: Multiple Regression w/ Polynomial-in-Y?"
- In reply to: Carl Devore: "Re: Numerical Differentiation in C"
- Next in thread: r5: "Re: Numerical Differentiation in C"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|