Better way to find Finite Difference

Click For Summary

Discussion Overview

The discussion revolves around methods for efficiently calculating the finite difference of a function with multiple components, specifically focusing on the construction of the derivative function ##\psi'## from the original function ##\psi##. Participants explore various approaches, computational speed, and algorithm stability without reaching a consensus on the best method.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant suggests using a forward finite difference for the first ##N-1## components and a backward finite difference for the last component to construct ##\psi'##.
  • Another participant emphasizes the importance of finding a stable and accurate algorithm for the specific application, questioning what "fast" means in this context.
  • Some participants propose using a simple difference approximation, ##\psi'_n \approx \psi_{n} - \psi_{n-1}##, while discussing the implications of accuracy and convergence.
  • There is mention of using analytic functions for direct differentiation, but some participants note that their functions are not analytic.
  • Extrapolation methods for estimating boundary values of ##\psi'## are suggested, particularly in the absence of boundary conditions.
  • Rolling splines and multipoint approximations are introduced as alternative methods for approximating derivatives.
  • A participant expresses frustration over the lack of clarity in the problem being addressed, emphasizing the need for more context to provide effective advice.
  • Ultimately, one participant reports having successfully used a built-in function for their needs, indicating satisfaction with that approach.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method for calculating the finite difference. Various competing views and approaches are presented, with some participants advocating for specific techniques while others raise questions about their applicability and effectiveness.

Contextual Notes

Participants express uncertainty regarding the definitions of "fast" and "accurate" in the context of their algorithms. The discussion also highlights the dependence on specific application details, which are not fully provided, leading to varied suggestions and approaches.

Who May Find This Useful

This discussion may be useful for individuals interested in numerical methods for derivatives, particularly in computational contexts where efficiency and accuracy are critical. It may also benefit those exploring various finite difference techniques and their applications in different scenarios.

member 428835
Given a function ##\psi## having ##N## components, how would you (as fast as possible) construct ##\psi'## also having ##N## components? I thought about taking a forward finite difference approach on the first ##N-1## components of ##\psi## to generate ##\psi'## and then a backward finite difference approach to generate the last (##Nth##) component of ##\psi'##.

Any faster ideas or better ways? Thanks!
 
Physics news on Phys.org
What do you mean by fast? First thing that comes to mind is computation speed on a computer. If this is the case I recommend finding a stable and accurate algorithm for your application (BTW what would that be?) and optimize later if required. Using a canned solver is often the way to go. Sometimes choosing a "slower" algorithm step is less computation because fewer integration steps are required for the computation. All depends on what one is doing. You haven't supplied any info in that regard.
 
Paul Colby said:
What do you mean by fast? First thing that comes to mind is computation speed on a computer. If this is the case I recommend finding a stable and accurate algorithm for your application (BTW what would that be?) and optimize later if required. Using a canned solver is often the way to go. Sometimes choosing a "slower" algorithm step is less computation because fewer integration steps are required for the computation. All depends on what one is doing. You haven't supplied any info in that regard.
By fast I refer to computation time. That's why I'm here: to get others' opinions of a stable algorithm. The application is difficult to explain, but I need to compute ##\psi'##. Not solving a PDE though. So a canned solver is your recommendation?
 
joshmccraney said:
So a canned solver is your recommendation?
Okay, what ever. I assume you have ##\psi_n## for ##n=1## to ##N## and you would like ##\psi'_n## with no discussion of accuracy or constrains. What's wrong with ##\psi'_n \approx \psi_{n} - \psi_{n-1}##?

Also, if ##\psi(x)## is given as an analytic function, take the derivative and evaluate ##\psi'(x_n)## works very well.
 
Paul Colby said:
Okay, what ever. I assume you have ##\psi_n## for ##n=1## to ##N## and you would like ##\psi'_n## with no discussion of accuracy or constrains. What's wrong with ##\psi'_n \approx \psi_{n} - \psi_{n-1}##?

Accuracy of the technique is not an issue so long as it converges "reasonably well" (say decreasing step size by half leaves an error estimate of 1%). Since the step size is smaller than 1, so far I've been using ##\psi'_n(x) \approx (\psi_{n} - \psi_{n-1})/dx## where ##dx## is the step size. Even if ##dx=1##, the numerical technique you suggest (which is also what I've been using) would give me ##N-1## values of ##\psi## unless I use a backward/forward technique on the last/first component, depending how you index. Is this okay?
Paul Colby said:
Also, if ##\psi(x)## is given as an analytic function, take the derivative and evaluate ##\psi'(x_n)## works very well.
Yea, I wish it were analytic but it's not, sadly.
 
joshmccraney said:
Is it clear what I'm trying to do?
No. "as long as it converges" - can't help with that given I don't know what "it" might be. I might suggest using two inboard values of ##\psi'## to extrapolate the missing end points. Good luck.
 
Sorry, "it" refers to the derivative, ##\psi'##. Hmmmm so you're saying to compute the interior components of ##\psi'## and the extrapolate to find ##\psi_1,\psi_N##?
 
joshmccraney said:
Sorry, "it" refers to the derivative, ##\psi'##. Hmmmm so you're saying to compute the interior components of ##\psi'## and the extrapolate to find ##\psi_1,\psi_N##?
I said extrapolate ##\psi'## not ##\psi##. In the absence of other information like boundary conditions at ##n=1## and or ##n=N## such as one might find in a physical problem what else would one do?
 
Rolling splines and choose a spline function with a simple derivative .
 
  • Like
Likes   Reactions: Paul Colby
  • #10
Paul Colby said:
I said extrapolate ##\psi'## not ##\psi##. In the absence of other information like boundary conditions at ##n=1## and or ##n=N## such as one might find in a physical problem what else would one do?
Sorry, that's what I meant, extrapolate ##\psi'##. Thanks to you both!
 
  • #12
You're solving an ODE. Please give a decent idea what the problem is that you're trying to solve. It's very hard to give advice without adequate information.
 
  • #13
It's ok, I ended up using a built in function, and it works very well and efficient. Thank you all for input though!
 

Similar threads

Replies
2
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
10
Views
101
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K