Can finite difference method can be expressed with diff function?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!