Matlab finite difference schemes

In summary, the conversation is about a problem with using finite difference schemes (DS) on Matlab. The person needs help writing the schemes in Matlab, specifically for higher orders such as u_xxx, u_yyy, etc. The suggested solution is to use a coefficients matrix to multiply with a vectorized data grid. The matrix is a block diagonal matrix with identical band matrices, but the top and bottom rows can be excluded since u_x(i,j) is not evaluated at the end points. The matrix can also be used for higher dimensions, but it becomes large quickly.
  • #1
micheal9000
2
0
I have big problem with finite difference schemes (DS) on Matlab. I need write DS on Matlab, example:
u_x=(u_(i+1,j)-u_(i-1,j))/2, we choose step is 1.
On Matlab:
u_x=(u( :,[2:n,n])-u( :,[1,1:n-1]))/2
And I can write u_y, u_xx, u_yy, u_xy. But now, I need to write for higher order, example, u_xxx, u_yyy, u_xxy, u_xyy, u_xxxx, u_yyyy, u_xxyy, u_xyyy, u_xxxy. From 3rd order, I cannot do it. Please help me. Many thanks.
P/s: I just need on Matlab code, I can write the schemes in mathematical form.
 
Last edited:
Physics news on Phys.org
  • #2
If you have the difference scheme, then a simple way to do it (for problems of low dimensions) is to vectorize the data points and use a coefficients matrix to multiply said vector with. These are typically (sparse) band matrices (blockband matrices in the general n-dimensional case), so the diag function is handy. In your example, this blockband matrix is a block diagonal matrix, where each block in the main diagonal are identical band matrices that consists of diagonals of 1/2 and -1/2 above and below the main diagonal by one diagonal respectively. You just need to be careful with the end points. In your example, you choose not to evaluate u_x(i,j) at the end points, so you don't technically need the top and bottom row of the band matrix. So if you have a n x n data grid, the matrix will be of the size (n2-n) x n2.

This works for higher dimensions as well, but the matrix gets very large (but sparse) quickly.

EDIT: Fixed mistake.
 
Last edited:

FAQ: Matlab finite difference schemes

1. What is a finite difference scheme in Matlab?

A finite difference scheme in Matlab is a numerical method used to approximate solutions to differential equations by discretizing the domain into a finite number of points and approximating derivatives using finite difference approximations.

2. How do you implement a finite difference scheme in Matlab?

To implement a finite difference scheme in Matlab, you first need to discretize the domain into a finite number of points. Then, you can use the appropriate finite difference approximations to approximate derivatives at each point. Finally, you can use a loop or vectorization to iterate through the points and solve for the solution at each point.

3. What are the advantages of using finite difference schemes in Matlab?

Finite difference schemes in Matlab are advantageous because they are relatively easy to implement and can handle complex geometries and boundary conditions. They also provide accurate solutions for a wide range of differential equations.

4. What are the limitations of finite difference schemes in Matlab?

One limitation of finite difference schemes in Matlab is that they may not be as accurate as other numerical methods such as finite element methods. They also require a fine discretization of the domain to obtain accurate solutions, which can be computationally expensive.

5. How do you choose the appropriate finite difference scheme in Matlab for a specific problem?

The choice of finite difference scheme in Matlab depends on the type of differential equation being solved, the complexity of the geometry and boundary conditions, and the desired accuracy of the solution. It is important to carefully study the problem and its requirements before selecting the appropriate finite difference scheme.

Similar threads

Replies
2
Views
3K
Replies
5
Views
2K
Replies
3
Views
3K
Replies
4
Views
3K
Replies
1
Views
1K
Replies
11
Views
4K
Replies
8
Views
2K
Replies
2
Views
1K
Replies
1
Views
4K
Back
Top