Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A Better way to find Finite Difference

  1. Oct 16, 2017 #1

    joshmccraney

    User Avatar
    Gold Member

    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!
     
  2. jcsd
  3. Oct 16, 2017 #2

    Paul Colby

    User Avatar
    Gold Member

    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.
     
  4. Oct 16, 2017 #3

    joshmccraney

    User Avatar
    Gold Member

    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?
     
  5. Oct 16, 2017 #4

    Paul Colby

    User Avatar
    Gold Member

    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.
     
  6. Oct 16, 2017 #5

    joshmccraney

    User Avatar
    Gold Member

    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?
    Yea, I wish it were analytic but it's not, sadly.
     
  7. Oct 16, 2017 #6

    Paul Colby

    User Avatar
    Gold Member

    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.
     
  8. Oct 16, 2017 #7

    joshmccraney

    User Avatar
    Gold Member

    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##?
     
  9. Oct 16, 2017 #8

    Paul Colby

    User Avatar
    Gold Member

    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?
     
  10. Oct 16, 2017 #9

    Nidum

    User Avatar
    Science Advisor
    Gold Member

    Rolling splines and choose a spline function with a simple derivative .
     
  11. Oct 16, 2017 #10

    joshmccraney

    User Avatar
    Gold Member

    Sorry, that's what I meant, extrapolate ##\psi'##. Thanks to you both!
     
  12. Oct 17, 2017 #11

    Stephen Tashi

    User Avatar
    Science Advisor

  13. Oct 18, 2017 #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.
     
  14. Oct 18, 2017 #13

    joshmccraney

    User Avatar
    Gold Member

    It's ok, I ended up using a built in function, and it works very well and efficient. Thank you all for input though!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Better way to find Finite Difference
Loading...