I saw in a code for discretization of something like $\frac{d^2T(x)}{d^2x}$ , ( $x = sin(\theta)$ ) tries

   !============== here are some defined variables
   deltaTheta = pi/150
   deltax(i) = cos(theta(i)) * deltaTheta  
   dx = 0.5*(deltax(i) + deltax(i+1))
   dx1 = 0.5*(deltax(i-1)+ deltax(i))
   !============== here is the discretization that I am talking about
   ... = ((T(i+1) - T(i))/dx - (T(i) - T(i-1))/dx1)/(0.5 *(dx + dx1))

this discretization was for non-boundary cites; what does this discretization called?

  • $\begingroup$ Do you mean beyond being called the three point stencil? Or are you talking about the choice of grid points? $\endgroup$
    – origimbo
    Nov 10 '17 at 16:16
  • $\begingroup$ @origimbo What I don't understand are defining and usage of "dx" and "dx1" $\endgroup$
    – Mr. Who
    Nov 10 '17 at 18:32
  • $\begingroup$ The three points might have different separations. $\endgroup$
    – nicoguaro
    Nov 10 '17 at 19:21

It is just the computation of the second derivative from three non-equidistant points. It is computed by first computing (an approximation of) the derivatives on each of the two intervals adjacent to point $i$ using $$ \frac{T(i+1)-T(i)}{\Delta(i+1)} $$ and $$ \frac{T(i)-T(i-1)}{\Delta(i)} $$ and then computing (an approximation of) the second derivative by taking a finite difference stencil with regard to the midpoints of the two intervals: $$ \frac{ \frac{T(i+1)-T(i)}{\Delta(i+1)} - \frac{T(i)-T(i-1)}{\Delta(i)} }{\frac{\Delta(i+1)+\Delta(i)}{2}} $$ Here, $\Delta(i+1)=x(i+1)-x(i)$ and $\Delta(i)=x(i)-x(i-1)$ are the dx1 and dx terms in the formula of the code you're looking at.

I have no idea how this relates to the dx and dx1 variables -- these look wrong to me since they are not increments but averages of the deltax(i) which themselves are not deltas (differences) but point locations as far as I can see. I can't seem to see that this choice of variable names or expressions makes sense.

  • 1
    $\begingroup$ thanks for the reply, since x = sin(\theta) then dx = cos(\theta) d\theta so detlax is really a difference; all the points that you mentioned make sense to me. $\endgroup$
    – Mr. Who
    Nov 11 '17 at 18:12
  • 1
    $\begingroup$ BTW, thanks for your informative website, very glad to know you. $\endgroup$
    – Mr. Who
    Nov 11 '17 at 18:42

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.