Better way to find Finite Difference

In summary, the conversation discusses ways to efficiently construct a function ##\psi'## with ##N## components. Suggestions include using a forward finite difference approach on the first ##N-1## components and a backward finite difference approach on the last component, or using a built-in solver. Other options mentioned include taking the derivative of an analytic function, extrapolating the missing endpoints, and using multipoint approximations. The conversation also highlights the importance of considering accuracy and convergence when choosing a method, and the need for more information about the specific problem being solved.
  • #1
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
  • #2
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.
 
  • #3
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?
 
  • #4
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.
 
  • #5
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.
 
  • #6
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.
 
  • #7
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##?
 
  • #8
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?
 
  • #9
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!
 

1. What is the finite difference method?

The finite difference method is a numerical technique used to approximate solutions to differential equations. It involves dividing a continuous function into discrete points and approximating the derivatives at those points using finite differences.

2. Why is the finite difference method used?

The finite difference method is used because it is a simple and efficient way to approximate solutions to differential equations. It is also a versatile method that can be applied to a wide range of problems in various fields such as engineering, physics, and finance.

3. What are the advantages of using the finite difference method?

One advantage of the finite difference method is its simplicity, making it easy to implement and understand. It also does not require complicated mathematical techniques, making it accessible to a wider range of users. Additionally, it can handle complex boundary conditions and can be applied to both linear and nonlinear problems.

4. Are there any limitations to the finite difference method?

Yes, there are some limitations to the finite difference method. It can only provide approximate solutions and may introduce errors due to the discretization of the function. It also requires a sufficiently small step size to accurately approximate the derivatives, which can increase computation time.

5. How can the finite difference method be improved?

There are several ways to improve the finite difference method, such as using higher-order schemes to reduce errors and improve accuracy. Adaptive mesh refinement techniques can also be used to adjust the step size in areas where the function varies more rapidly. Additionally, combining the finite difference method with other numerical techniques, such as finite element or finite volume methods, can improve its performance for certain types of problems.

Similar threads

  • Differential Equations
Replies
5
Views
1K
  • Differential Geometry
Replies
1
Views
1K
Replies
0
Views
275
Replies
6
Views
2K
  • High Energy, Nuclear, Particle Physics
Replies
8
Views
714
  • Differential Equations
Replies
3
Views
1K
  • Differential Equations
Replies
3
Views
2K
Replies
7
Views
1K
Replies
2
Views
522
Replies
2
Views
1K
Back
Top