Backwards difference matrix divided by negative delta x?

In summary: AIn summary, the author attempted to solve a second order differential equation using a forwards, centered and backwards difference matrix. However, problems arose when trying to apply the backwards difference matrix. The author found that the resulting solution vector was five orders of magnitude larger than the solutions obtained in the forward and centered cases. The author also changed the variables in the backwards difference matrix to see if this would help, but the solution vector still appeared to be transposed.
  • #1
kostoglotov
234
6
An exercise in my text requires me to (in MATLAB) generate a numeric solution to a given second order differential equation in three different ways using a forwards, centered and backwards difference matrix. I got reasonable answers for [itex]\vec{u}[/itex] that agreed with each other (approximately) for the forward and centered cases, but I had problems getting the backwards case to work...I did get it to work, but I want to know if what I did to get it to work was correct or a fluke or incorrect.

Here is the exercise specifically:

d6QDYO1.jpg


imgur link: http://i.imgur.com/d6QDYO1.jpg

I used 10x10 difference matrices in MATLAB, but I will give 4x4 examples here below of the pattern I used in those matrices

Forward difference matrix

[tex]\begin{bmatrix}1 & 0 & 0 & 0\\ -1 & 1 & 0 & 0\\ 0 & -1 & 1 & 0\\ 0 & 0 & -1 & 1\end{bmatrix}[/tex]

Centered difference matrix (with division by [itex]2\Delta x[/itex])

[tex]\begin{bmatrix}1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ -1 & 0 & 1 & 0\\ 0 & -1 & 0 & 1\end{bmatrix}[/tex]

Backward difference matrix

[tex]\begin{bmatrix}-1 & 1 & 0 & 0\\ 0 & -1 & 1 & 0\\ 0 & 0 & -1 & 1\\ 0 & 0 & 0 & -1\end{bmatrix}[/tex]

For the forward and centered, like I said, I got reasonable results that agreed with each other approximately and agree trend wise when graphed.

Tow problems occurred when trying to apply the backwards difference matrix

1) first off, the resulting [itex]\vec{u}[/itex] was some 5 orders of magnitude larger than the resulting [itex]\vec{u}[/itex] obtained in the forward and centered cases.

I thought to myself that since it's a backwards difference, then in the same analogy to calculus, maybe the [itex]\Delta x[/itex] should be negative as well. So to solve the given diff eq I then put the negative signs in the appropriate places. The second order differential term wouldn't have a negative sign in front since its equivalent second different matrix will be divided by [itex](\Delta x)^2[/itex]. This produced a very similar vector to the two solution vectors from forward and centered cases, BUT

2) the solution vector obtained after making the change [itex]\Delta x < 0[/itex] was a "transposed vector" compared to the other two solution vectors. Ie, the first and last, and second and second last, and third and third last, etc entries were swapped around...and I can't figure out why.

If in the backwards case I make [itex]\Delta x < 0[/itex] and apply a "vector transpose" to the solution vector then it agrees roughly with the forward and centered cases.

1) Am I correct about [itex]\Delta x < 0[/itex] for the backwards case?

and 2) why was the solution vector "transposed"?
 
Physics news on Phys.org
  • #2
kostoglotov said:
An exercise in my text requires me to (in MATLAB) generate a numeric solution to a given second order differential equation in three different ways using a forwards, centered and backwards difference matrix. I got reasonable answers for [itex]\vec{u}[/itex] that agreed with each other (approximately) for the forward and centered cases, but I had problems getting the backwards case to work...I did get it to work, but I want to know if what I did to get it to work was correct or a fluke or incorrect.

Forward difference matrix

[tex]\begin{bmatrix}1 & 0 & 0 & 0\\ -1 & 1 & 0 & 0\\ 0 & -1 & 1 & 0\\ 0 & 0 & -1 & 1\end{bmatrix}[/tex]Backward difference matrix

[tex]\begin{bmatrix}-1 & 1 & 0 & 0\\ 0 & -1 & 1 & 0\\ 0 & 0 & -1 & 1\\ 0 & 0 & 0 & -1\end{bmatrix}[/tex]

The general form for the backward difference is ## u'_{i} \approx \frac{ u_{i+1} - u_{i} }{\Delta x}, ## right?
So this would look like
##\frac{1}{\Delta x} \begin{bmatrix}-1 & 1 \end{bmatrix} \begin{bmatrix}u_1 \\ u_2\end{bmatrix} = u'_1##
This seems like the right backbone for the problem. Make sure that your stand-alone term in the bottom right corner is used to enforce a boundary condition or something.

As far as the negative to transpose business...if you change delta x to negative delta x ( you shouldn't ), then you will get the same as the transpose of your first matrix (forward difference).
 
  • #3
Also, what were you using for your second derivative?
 
  • #4
RUber said:
Also, what were you using for your second derivative?

[itex]A^TA[/itex]
 

1. What is a backwards difference matrix?

A backwards difference matrix is a matrix used to approximate the derivative of a function at a given point. It is constructed by taking the difference between the function values at a point and the previous point, and dividing by the step size.

2. What is a negative delta x?

Delta x, or ∆x, represents the change in the independent variable (usually denoted as x) in a function. A negative delta x simply means that the change in x is in the opposite direction, or decreasing. It is often used in the context of calculating derivatives.

3. How is a backwards difference matrix divided by negative delta x calculated?

To calculate a backwards difference matrix divided by negative delta x, you simply divide each element in the matrix by the negative value of delta x. This results in a matrix that approximates the derivative of the function at each point.

4. What is the purpose of using a backwards difference matrix divided by negative delta x?

The purpose of using a backwards difference matrix divided by negative delta x is to approximate the derivative of a function at a given point. This can be useful in cases where the function is complex or difficult to differentiate analytically, allowing for an easier and more efficient calculation of the derivative.

5. Can a backwards difference matrix divided by negative delta x accurately calculate derivatives?

While a backwards difference matrix divided by negative delta x can provide a good approximation of the derivative, it is not always accurate. The accuracy depends on the step size used and the complexity of the function. In some cases, a smaller step size may be needed to achieve a more accurate approximation.

Similar threads

  • Linear and Abstract Algebra
Replies
8
Views
797
  • Linear and Abstract Algebra
Replies
6
Views
529
  • Linear and Abstract Algebra
Replies
12
Views
2K
Replies
27
Views
1K
  • Linear and Abstract Algebra
Replies
3
Views
1K
  • Linear and Abstract Algebra
Replies
2
Views
2K
  • Linear and Abstract Algebra
Replies
2
Views
1K
  • Linear and Abstract Algebra
Replies
1
Views
714
  • Linear and Abstract Algebra
Replies
11
Views
2K
  • Linear and Abstract Algebra
Replies
1
Views
2K
Back
Top