# 2d finite differences implementation for a Numerical Analysis lecture

**URL:** <https://discourse.julialang.org/t/2d-finite-differences-implementation-for-a-numerical-analysis-lecture/70222>\
**Category:** Performance\
**Tags:** numerics, finitediff\
**Created:** [October 22, 2021, 3:32pm UTC](https://discourse.julialang.org/t/2d-finite-differences-implementation-for-a-numerical-analysis-lecture/70222 "2021-10-22T15:32:21Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 23, 2022, 12:22am UTC](https://discourse.julialang.org/t/2d-finite-differences-implementation-for-a-numerical-analysis-lecture/70222/5 "2022-06-23T00:22:31Z")

</div>

> [@vicdolean](#):
>
> I all want are simple teaching codes where I can illustrate all the basic concepts on finite differences in a genuinely 2d implementation (no kronecker of 1d!)

See, for example, [this post](https://discourse.julialang.org/t/seemingly-unnecessary-allocation-within-for-loop/72556/8), which provides a simple N-dimensional implementation of a finite-difference method for a wave equation using a leapfrog explicit timestepping scheme. It would be pretty easy to change it to the diffusion equation, too.

Among other things, it illustrates computing the finite-difference Laplacian in N dimensions cleanly and efficiently using Julia’s Cartesian-indexing code, and the useful technique of “ghost cells” for boundary conditions (which allow you to separate the boundary-condition code from the finite-difference code).

(Whoops, sorry, I see that this is an old thread that was recently revived.)

---

_[View the full topic](https://discourse.julialang.org/t/2d-finite-differences-implementation-for-a-numerical-analysis-lecture/70222)._
