Previous | Next --- Slide 30 of 44
Back to Lecture Thumbnails

Why does the grid have -4 and 4 1's when the equation is +4 with 4 -1's?


We're approaching the local minimum here, so value should be $\dfrac{u_{t+1} - u_{t}}{h^2}$, which is what we have here.


@cou Suppose I have a function $f(x)$, but can only evaluate this function as a "black box," i.e., I don't know the explicit form of the function, but can only ask for its value at given points. How can I approximate its first derivative? Well, assuming the function is differentiable, the definition of the derivative is

$$ f^\prime(x) := \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}$$

So, if I've sampled the function $f$ onto a regularly spaced grid with values $f_1, f_2, \ldots$ separated by a small but fixed distance $h$, I can approximate the derivative as

$$ f^\prime_{i+1/2} := \frac{f_{i+1}-f_i}{h}. $$

The strange index on $f'$ reflects the fact that this gives me an approximation of the derivative at the location "$i+1/2$", i.e., halfway between $i$ and $i+1$. Now suppose I want to approximate the second derivative. Well, I now have another grid of regularly sampled values $f^\prime_{1/2}, f^\prime_{3/2}, \ldots$, again spaced by a distance $h$, and so I can again apply the same approximation to get

$$ f^{\prime\prime}i := \frac{f^\prime{i+1/2}-f^\prime_{i-1/2}}{h}. $$

If I now plug in the expression for $f'{i+1/2}$ and $f'{i-1/2}$ into the expression for $f''_i$, I get

$$ f''i := \frac{\frac{f{i+1}-f_i}{h}-\frac{f_{i}-f_i-1}{h}}{h} $$

which simplifies to just

$$ f''i = \frac{f{i+1}-2f_i+f_i-1}{h^2}. $$

In other words, in 1D, I can approximate the 2nd derivative by adding the value of my two neighbors, subtracting twice my value, and dividing by the square of the grid spacing.

Suppose now that I want to approximate, in 2D, the Laplacian

$$ \Delta f = \frac{\partial^2 f}{\partial x^2} + \frac{\partial^2 f}{\partial y^2} $$

All I have to do is repeat this procedure in both the $x$ and $y$ directions. In the end, the formula will say: add up the values of the four neighbors (top, bottom, left, and right), subtract four times the value at the center (since both $x$ and $y$ directions each contribute two instances of the middle value), and divide by $h^2$. That's the expression above says.


@cou Whoops; I realized you're just asking about the sign! Yes, that's a sign error. But it's important to know that different people and different communities (physicists, geometers, etc.) will adopt opposite sign conventions for the Laplacian. For some it's positive semidefinite; for others it's negative semidefinite. So, just like the symbol used for the Laplacian, you have to be careful! :-)