Calculating mixed partial derivatives of a function A(x,y)

조회 수: 38 (최근 30일)
Caleb
Caleb 2016년 4월 3일
댓글: Roger Stafford 2016년 4월 3일
I have a script in MATLAB to calculate the value of a function A. I have also programmed the analytic derivatives of A with respect to x and y and also d2A/dxdy. Now, I want to check that my analytic derivatives are correct with a numerical validation. The form of the function is very complicated, so it's not so easy as just re-checking my math. How would you program the numerical derivative of a mixed partial derivative in MATLAB?

채택된 답변

Roger Stafford
Roger Stafford 2016년 4월 3일
편집: Roger Stafford 2016년 4월 3일
syms x y
f(x,y) = x*sin(y);
d2fdxdy = diff(diff(f,x),y); % = cos(y)
Another way is:
syms x y
diff(x*sin(x*y),x,y); % = 2*x*cos(x*y)-x^2*y*sin(x*y)
  댓글 수: 3
Caleb
Caleb 2016년 4월 3일
Additionally, if my function contains expressions that are functions of x and y, such as: A(x,y) = x*cos(y) + y*C(x,y), how is that handled?
Roger Stafford
Roger Stafford 2016년 4월 3일
@Caleb: Obviously you cannot find derivatives of such a function without having an explicit expression for C(x,y).
C(x,y) = ..... % <-- whatever you define C as in terms of x and y
A(x,y) = x*cos(y) + y*C(x,y);
d2Adxdy = diff(A,x,y);
See:
http://www.mathworks.com/help/symbolic/diff.html

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

추가 답변 (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