Why gradient and diff give different results
12 ビュー (過去 30 日間)
古いコメントを表示
Hi there, I am trying to derive a force from given potential, that F = - gradient of potential if mass is one. To test it, I try to set up a very simple 2D case with potential is
A=[1 2 3; 3 2 6; -2 -7 2];
dx=1;
dy=1;
[fx, fy]=gradient(A, dx, dy);
Now I am thinking to use diff instead. ax=diff(A')/dx; ay=diff(A)/dy;
Ignore the fact that diff will lose 1 row or column, the numbers of results for those two methods are not in agreement as well. So why is that? Besides differentiation, what else gradient calculate?
0 件のコメント
採用された回答
the cyclist
2016 年 2 月 8 日
The exact algorithm that gradient uses is given at the bottom of the documentation page for gradient.
It uses the central difference (two-sided difference, divided by 2) for central points, and single-side difference at the edges.
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!