Integrate a function after having differenciated it
조회 수: 8 (최근 30일)
이전 댓글 표시
Adrian Anton Alvarez
2020년 12월 15일
댓글: Adrian Anton Alvarez
2020년 12월 16일
I would like to differenciate a function (2 variables) and after that integrate it, but its giving me errors all the time. You can see here an extract of the code. Does anybody now how can I do this?
u = @(x,y) sqrt(1-x).*y;
duxx = @(x,y) diff(u(x,y),x,2);
k = (1/2)*integral2(duxx,0,1,0,1);
댓글 수: 0
채택된 답변
Walter Roberson
2020년 12월 16일
편집: Walter Roberson
2020년 12월 16일
integral2 is a numeric integration routine. It will pass the function handle two arrays of values, and must return something the same size.
With your function handle, u(x, y) will be invoked, passing in the arrays. Your u is vectorized so it will return a numeric array.
The numeric array will then be passed as the first parameter to diff(), and the numeric x will be passed as the second parameter, and 2 will be passed as the third.
https://www.mathworks.com/help/matlab/ref/diff.html shows that three parameters are possible for diff() but only when the second is a positive integer representing the difference number and the third is the dimension number. The array of x values is not a dimension number.
You have gotten confused between the numeric diff() function and the symbolic diff() function which is calculus. The calculus diff does not work on function handles, just symbolic expressions and symbolic functions.
sym x y
duxx = matlabFunction(diff(u(x,y), x, 2), 'vars', [x, y])
integral2(duxx, etc)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!