Homework Help: Gradient and Laplacian of three functions

1. Jan 10, 2013

sciwizeh

Hello, I've been reading up on Smoothed Particle Hydrodynamics. While reading some papers I found some math that I do not know how to do because I never took multi variable calculus. I need the gradient and laplacian of all three of the following functions ( h is a constant ):

Wpoly6(r,h)=$\frac{315}{64\pi h^{9}}\begin{cases} (h^{2}-|r|^{2})^{3} & 0\leq r\leq h \\ 0 & \text{ otherwise } \end{cases}$
Wspiky(r,h)=$\frac{15}{\pi h^{6}}\begin{cases} (h-|r|)^{3} & 0\leq r\leq h \\ 0 & \text{ otherwise } \end{cases}$
Wviscosity(r,h)=$\frac{15}{2\pi h^{3}}\begin{cases} -\frac{r^{3}}{2h^{3}}+\frac{r^{2}}{h^{2}}+\frac{h}{2r} & 0\leq r\leq h \\ 0 & \text{ otherwise } \end{cases}$
note: almost copied the last one wrong, the last term of the top is h over 2r and the other terms are r's over h's

If I understand correctly the magnitude operation makes this an essentially 1 dimensional problem and the gradient is the derivative and the lapracian is the second derivative. Am I right in this thought? If not what does it mean?
I am very rusty in my calculus, so even if that is true, I would prefer the answers rather than the procedure. The only thing I need in order to translate the papers to an implementation is these 6 more equations.

2. Jan 11, 2013

SteamKing

Staff Emeritus
Gradient and Laplacian operators are covered in multi-variable or vector calculus.

I would start there.

3. Jan 11, 2013

sciwizeh

Yes, I know, but I am no longer in school and I never took multi-variable calculus. I also have read the wikipedia page on them and I get the principal, but I don't know how to deal with the magnitude operation, also it's been years since I've done any kind of calculus work so I don't remember much. I also just need the equations to implement in code.

Because this is a homework help forum and you seem reluctant to just answer the question, I want to be clear, this is NOT homework, I'm independently trying to implement smoothed particle hydrodynamics. The papers give the functions above, but most of the formula's use the gradient of them or the laplacian without actually giving them.

4. Jan 11, 2013

Bipolarity

Since this is not for homework work, you kind of posted in the wrong forum, but I'll help you out anyway because your intention seems to be in implementing it in code.

Gradient (note that it is vector-valued; you would need to use several variables to implement this in your code; one for each component, or you could use an array/list):

$$∇W = <\frac{∂W}{∂r},\frac{∂W}{∂h}>$$

Laplacian (scalar valued, you only need one variable to store the Laplacian):

$$ΔW = ∇ \cdot ∇W$$

BiP

5. Jan 11, 2013

sciwizeh

But it is:
Technically this would be under the heading of "just independent study." (No?)

Anyhow, h is actually a constant, the vector is r, so it would be:
$∇W = <\frac{∂W}{∂r_x},\frac{∂W}{∂r_y},\frac{∂W}{∂r_z}>$
correct?

Digging through more papers I've found: (note, I've also changed r to r with arrow to better indicate vector valued)
$W_{poly6}(\vec{r},h)=\frac{315}{64\pi h^{9}}\begin{cases} (h^{2}-|r|^{2})^{3} & 0\leq |r|\leq h \\ 0 & \text{ otherwise } \end{cases}$
$\bigtriangledown W_{poly6}(\vec{r},h)=(-6)\frac{315}{64\pi h^{9}}\begin{cases} (h^{2}-|r|^{2})^{2} \begin{pmatrix} r_{x}\\ r_{y}\\ r_{z} \end{pmatrix} & 0\leq |r|\leq h \\ \mathbf{0} & \text{ otherwise } \end{cases}$
$\bigtriangledown^{2} W_{poly6}(\vec{r},h)=\frac{315}{64\pi h^{9}}\begin{cases} -18(h^{2}-|r|^{2})^{2}+24|r|^{2}(h^2-|r|^2) & 0\leq |r|\leq h \\ 0 & \text{ otherwise } \end{cases}$
$W_{viscosity}(\vec{r},h)=\frac{15}{2\pi h^{3}}\begin{cases} -\frac{|r|^{3}}{2h^{3}}+\frac{|r|^{2}}{h^{2}}+\frac{h}{ 2|r|} & 0\leq |r|\leq h \\ 0 & \text{ otherwise } \end{cases}$
$\bigtriangledown W_{viscosity}(\vec{r},h)=\frac{15}{2\pi h^{3}}\begin{cases} -\frac{3|r|}{2h^{3}}+\frac{2}{h^{2}}+\frac{h}{ 2|r|^3} \begin{pmatrix} r_x\\ r_y\\ r_z \end{pmatrix} & 0\leq |r|\leq h \\ 0 & \text{ otherwise } \end{cases}$
$\bigtriangledown^2 W_{viscosity}(\vec{r},h)=(6)\frac{15}{2\pi h^{3}}\begin{cases} (\frac{1}{h^3})(h-|r|) & 0\leq |r|\leq h \\ 0 & \text{ otherwise } \end{cases}$

Are these correct? I sort of get how to get the gradient, but I don't understand the Lapracian at all.
With these equations I could implement what I need to, however one paper mentions a stability issue if the third W function is not used. So for completeness I need the gradient and lapracian of:

$W_{spiky}(\vec{r},h)=\frac{15}{\pi h^{6}}\begin{cases} (h-|r|)^{3} & 0\leq r\leq h \\ 0 & \text{ otherwise } \end{cases}$

Last edited: Jan 11, 2013