My Python Library For Finite Difference Method

• person123
In summary, the library is designed to help with the solution of finite difference problems, and is designed for use with boundary value problems.
person123
I recently made a Python library for modelling (very basic) finite difference problems. The Github readme goes into details of what it does and how it works, and I put together a Google Colab with some examples (diffusion, advection, water wave refraction) with interactive visuals.

I'd love to hear what people think: general feedback, if they're running into issues, things they would want to see included. It's still in an early phase, and I would like to add to it. If anyone wants to contribute, let me know!

Wrichik Basu
Off-topic: You could consider enabling Discussions in your repo.

person123
Wrichik Basu said:
Off-topic: You could consider enabling Discussions in your repo.
I enabled discussions :)
Feel free to post any thoughts, critiques you have with the project idea or issues you have using it, directions you would like to see it go, interest in collaboration etc.

Wrichik Basu
@person123, would your program be able to solve very elementary difference equation problems like this?
Find an equation of the function that contains the points (1, 1), (2, 8), (3, 27), (4, 64).

Mark44 said:
@person123, would your program be able to solve very elementary difference equation problems like this?
Find an equation of the function that contains the points (1, 1), (2, 8), (3, 27), (4, 64).

So far, I've just focused on specifying analytical equations as input, but getting numerical solutions as output. The user specifies initial conditions and boundary conditions for fields, and they see how the field evolves with time under differential equations. But the computation is performed numerically, and the solution is values at each point in the domain. Basically, it's been a tool for numerical models, not for analytical solutions. (I go into more details on what it can do in the github readme).

Is it possible we're thinking of two different things? Maybe you're thinking of interpolation using finite differences, like Lagrange interpolation, while I'm thinking of the finite difference method for numerical modeling (in contrast with finite volume and finite element). But I'm also not very familiar with the former, so maybe there's a connection I'm not seeing.

@Mark44 Looking at that page, it does seem like there's a connection. While my library can't do interpolation, it can approximate derivatives, seen in the "Relation With Derivatives" and "Higher-order differences" sections (this is actually critical for my library doing anything useful at all). Namely, given some arbitrary coordinates, and the derivative order, inputted as the following:

Python:
d2 = fd.Stencil([-1,0,1], der_order = 2)

It creates a "Stencil" object, a numerical approximation for the second derivative, and prints the equation (sadly not displayed in latex):

Finite approximation: f'' = [f(x-h) - 2f(x+0h) + f(x+h)] / [h^2]

This derivative approximation is then used for modeling the partial differential equation.

I think mathematically, this is similar to interpolating points with polynomials, since they both rely on Taylor series. But for numerical modeling, I think what you care about is constructing a numerical approximation from an analytical derivative, instead of constructing an analytical equation from numeric values. Maybe there would be an application for interpolation as well though, I'm not sure.

Mark44 said:
Could be, although it's been many years since I did anything with finite differences.
I think the confusion arises because of the difference between the terminology in the title, which is correct:
person123 said:
My Python Library For Finite Difference Method
and in the introduction in the first post, which is not
person123 said:
I recently made a Python library for modelling (very basic) finite difference problems.

Finite difference methods are a class of methods for numerically solving systems of (usually partial) differential equations with given boundary conditions: these are often referred to as boundary value problems (BVPs) to distinguish them from initial value problems (IVPs) for which other methods are used. Finite difference problems aren't really a thing, but if they were then they would be what @Mark44 had in mind.

So the introduction would be better phrased as "I recently made a Python library for modelling (very basic) systems of differential equations using finite difference methods" or "I recently made a Python library for numerical solution of (very basic) boundary value problems using finite difference methods".

Last edited:
person123 and Wrichik Basu
@pbuk Thank you, yes, it sounds like that was the source of the confusion. It looks like I made the post too long ago to edit, but that change would be more accurate.

berkeman

• Differential Equations
Replies
1
Views
1K
• Programming and Computer Science
Replies
8
Views
2K
• Programming and Computer Science
Replies
6
Views
1K
• Programming and Computer Science
Replies
15
Views
1K
• Differential Equations
Replies
16
Views
2K
• Differential Equations
Replies
1
Views
2K
• New Member Introductions
Replies
1
Views
118
• Differential Equations
Replies
1
Views
6K
• Calculus
Replies
6
Views
6K
• Differential Equations
Replies
1
Views
3K