about gradient and diff

조회 수: 6 (최근 30일)
Yuji Zhang
Yuji Zhang 2013년 6월 15일
The help of my matlab says: (in article "gradient -Gradient vector of scalar function")
-If x is a scalar, gradient(f,x) = diff(f, x).
This is wrong, right?
diff(f,2) should = diff( diff(f) ) % means 2nd order diff
while gradient (f, 2) means the grid increment is 2. which means, for a curve f-t, or f(t), t is a linear space and dt = t(2)-t(1) = 2
Let me know everybody~ Thanks~
  댓글 수: 5
Image Analyst
Image Analyst 2013년 6월 15일
How do you tell your code which one to use?
Yuji Zhang
Yuji Zhang 2013년 6월 15일
편집: Yuji Zhang 2013년 6월 15일
I think, if your input y is a symbolic function, like y = x^2, then gradient(y) is symbolic gradient.
If the y is a numerical curve, like y = [1 2 3 4 ....]; then gradient(y) is the numerical gradient.

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

채택된 답변

Walter Roberson
Walter Roberson 2013년 6월 15일
Symbolic gradient, http://www.mathworks.com/help/symbolic/gradient.html, is the gradient vector of a scalar function, but numeric gradient, http://www.mathworks.com/help/matlab/ref/gradient.html is just "Numerical gradient". It is numerical gradient for which the "2" would mean a point spacing of 2, and it is the symbolic gradient for which the "2" would mean double differentiation.
  댓글 수: 1
Yuji Zhang
Yuji Zhang 2013년 6월 15일
Hi Walter~
Nice explanation! Thank you so much! I didn't know there were two different gradient functions. Yea, I see - makes sense. These two gradient functions are in different contexts.
Thanks again~

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by