A Better way to find Finite Difference

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 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!
 
Back
Top