using quad2d
이전 댓글 표시
Hi, i am trying to use quad2d and running into the following problem: I've a functions defined , e.g.
f1 = @(x,y) x+y
f2 = @(x,y) x-y
f3 = @(x,y) x
f4 = @(x,y) y
I need to integrate dot([f1 f2], [f3 f4]). if I try quad2d(@(x,y) dot([f1 f2], [f3 f4]),a,b,c,d ) it isn't working. Any suggestions as how fix this? thanks
채택된 답변
추가 답변 (1개)
Walter Roberson
2011년 12월 18일
quad2d(@(x,y) dot([f1(x,y) f2(x,y)], [f3(x,y) f4(x,y)]),a,b,c,d )
댓글 수: 2
Aziz
2011년 12월 19일
Walter Roberson
2011년 12월 19일
The quad2d() reference says,
All input functions must be vectorized. The function Z=fun(X,Y) must accept 2-D matrices X and Y of the same size and return a matrix Z of corresponding values
However, when you supply matrix arguments, although each of f1, f2, f3, and f4 would return matrices, [f1(x,y) f2(x,y)] is going to be a 2D array with the pieces concatenated along the second dimension (horzcat), and likewise [f3(x,y) f4(x,y)] would be a 2D array with the pieces concatenated along the second dimension, and dot() applied to a pair of 2D arrays will apply the dot product along the first non-singular dimension (which will be the first dimension in this case), giving you a row vector of results rather than a 2D array.
Alternative code:
quad2d(@(x,y) reshape(f1(x(:),y(:)) .* f3(x(:), y(:)) + f2(x(:),y(:)) .* f4(x(:), y(:)), size(x)) )
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!