I am trying to understand the FDM which is a widely used method solving differential equations by using approximation below. $$\dfrac{\partial u}{\partial x}=\dfrac{u(i+1)-u(i-1)}{2\Delta x}$$ How can I apply the approximation the equation given below?

$$\dfrac{d}{dx}(z(x)\dfrac{d}{dx}u(x))=0$$ where $u(0)=a$ and $u(1)=b$

and $z(x)=1 $ for $0<x<0.5$, $z(x)=2 $ for $0.5<x<1$

So, after some derivation the equation becomes, $$\dfrac{z(i+1)-z(i-1)}{2\Delta x}\dfrac{u(i+1)-u(i-1)}{2\Delta x}+z(i)\dfrac{u(i+1)-2u(i)+u(i-1)}{2\Delta x}=0$$

How can I handle the discontinuity at 0.5?

  • $\begingroup$ seems to me that your intervals need to define a value at .5 and use it. As of now you're not defining z at that point. $\endgroup$
    – EMP
    Jun 25 '20 at 18:55
  • $\begingroup$ If you are interested in other approaches that can handle discontinuities take a look at finite volume method danieljfarrell.github.io/FVM $\endgroup$
    – boyfarrell
    Jun 25 '20 at 21:44
  • $\begingroup$ Or the finite element method, which also doesn't care whether or not $z(x)$ is continuous. $\endgroup$ Jun 26 '20 at 3:20

You're approaching this the wrong way by using the product rule of differentiation. Rather, making use of the fact that $$ \frac{\partial u(x_i)}{\partial x} \approx \frac{u_{i+1/2}-u_{i-1/2}}{\Delta x}, $$ the first step in finding what you need to do is to recognize that $$ z(x_i)\frac{\partial u(x_i)}{\partial x} \approx z_i \frac{u_{i+1/2}-u_{i-1/2}}{\Delta x} = \frac{z_i u_{i+1/2}-z_i u_{i-1/2}}{\Delta x}. $$

The second step is the applying the finite difference operation one more time: $$ \frac{\partial}{\partial x} \left[z(x_i)\frac{\partial u(x_i)}{\partial x} \right] \approx \frac{\frac{z_{i+1/2} u_{i+ 1}-z_{i+1/2} u_{i}}{\Delta x} - \frac{z_{i-1/2} u_{i}-z_{i-1/2} u_{i-1}}{\Delta x}}{\Delta x}. $$ This can be simplified to the following, more familiar form: $$ \frac{\partial}{\partial x} \left[z(x_i)\frac{\partial u(x_i)}{\partial x} \right] \approx \frac{z_{i+1/2} u_{i+ 1}-(z_{i+1/2} +z_{i-1/2}) u_{i} + z_{i-1/2} u_{i-1}}{\Delta x^2}. $$

  • $\begingroup$ Why product rule of differentiation gives wrong result? @Wolfgang Bangerth $\endgroup$ Jun 26 '20 at 7:26
  • $\begingroup$ @AldrichTaylor -- it's not that your approximation is wrong, it's just that you lose certain properties using that approach that are useful in the analysis and solution of the discretized form if you apply the product rule first. $\endgroup$ Jun 26 '20 at 15:49
  • $\begingroup$ Instead of using $\dfrac{\partial u}{\partial x}=\dfrac{u(i+1/2)-u(i-1/2)}{2\Delta x}$, can I use $\dfrac{\partial u}{\partial x}=\dfrac{u(i+1)-u(i-1)}{2\Delta x}$ approach? In your approch, I assume, you get mid points of the differential points. Am I rgiht? Is there a difference between your and my apporach? @WolfgangBangerth $\endgroup$ Jun 26 '20 at 17:01
  • $\begingroup$ If you take $\pm 1$, then you end up using only every second point on your mesh to define the finite difference approximation of $u$. If you look at how I wrote this down, you only need the half-mesh points for $z$, but not for $u$. $\endgroup$ Jun 26 '20 at 22:28

There's a really nice book by Li and Ito on the immersed interface method, which was designed to solve problems like yours. Chapter 2 describes 1D problems. Basically, the finite difference method works well when the coefficients are smooth, but when they're rapidly varying or have discontinuities things can go to hell very quickly. You can make it work by being very careful to put nodes right at the interface and making special choices in your finite difference stencils.

  • $\begingroup$ Seconding this. IIM is also pretty easy to implement yourself for a simple problem like this. However, if you are just learned about FDM, then one thing you have now learned is that FDM is not good at handling problems with discontinuities. FEM and FVM are much better at these types of problems, generally $\endgroup$
    – whpowell96
    Jun 26 '20 at 0:36
  • $\begingroup$ While IIM involves jump conditions of the solution and its derivative at the interface, there is no such condition here. $\endgroup$ Jun 26 '20 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.