필터 지우기
필터 지우기

Can finite difference method can be expressed with diff function?

조회 수: 2 (최근 30일)
mathango
mathango 2016년 5월 8일
댓글: Roger Stafford 2016년 5월 9일
Hi, Here is the finite difference example
i=2:n-1;
j=2:n-1;
B(i,j) = A(i+1,j) - 2*A(i,j) + A(i-1,j) + A(i,j+1) - 2*A(i,j) + A(i,j-1)
expanding it yields
B(i,j) = A(i+1,j) - *A(i,j)- *A(i,j) + A(i-1,j) + A(i,j+1)- *A(i,j)- *A(i,j) + A(i,j-1)
rearranging,
B(i,j) = {A(i+1,j) - *A(i,j)}- {*A(i,j) - A(i-1,j)} + {A(i,j+1)- *A(i,j)} - {*A(i,j) - A(i,j-1)}
then,
B = diff(A,?,?) - diff(A,?,?) + diff(A,?,?) - diff(A,?,?)
Can this arrangement be possible? if yes, then what are the values in the question marks.

답변 (1개)

Roger Stafford
Roger Stafford 2016년 5월 8일
편집: Roger Stafford 2016년 5월 8일
Assuming A is n x n,
B = diff(A,2,1)+diff(A,2,2);
The array B would be of n-2 x n-2 size. The second argument of 2 in each 'diff' indicates a "second" difference.
  댓글 수: 2
mathango
mathango 2016년 5월 9일
The equation does not work. Each diff result has different matrix size ( 3 x 5 and 5 x 3 for n=5) therefore sum of each diff does not work.
Roger Stafford
Roger Stafford 2016년 5월 9일
I'm sorry. I have corrected it to be what I think you asked for. The second difference operation shrinks the size down by two in the direction in which it is performed. Your expression did second differencing in two directions.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by