필터 지우기
필터 지우기

Numerical integration error for a function in x,y that can be analytically integrated!

조회 수: 1 (최근 30일)
Kobye
Kobye 2013년 10월 23일
답변: unami3 2016년 8월 23일
I am getting the error: "Error in integral2 (line 107)" when trying to numerically evaluate the below surface integral.
func2 = @(x,y) (50+x*cos(y))^3*(50+x*sin(y))+(50+x*cos(y))*(50+x*sin(y))^2;
integral2(func2,0,10,0,2*pi)
This integral has an analytical solution. Could someone help me understand why MATLAB is giving me this error?
I have also tried using quad2d with the same error, which at the base seems to be "Error using * - Inner matrix dimensions must agree" in both cases.

답변 (1개)

unami3
unami3 2016년 8월 23일
Hi Kobye!
I'm having problems with integral2 as well, but they're slightly different. Your problem is quite obvious & simple to fix though, so I thought I'd answer it quickly.
You need to put a period in front of multiplication, division, and power signs in func2 (i.e. you need to put .*, ./, and .^ instead of *, /, and ^). This small change is necessary because integral2 sends in arrays to func2 when it is evaluated and the periods indicate to Matlab that we are performing element-by-element operations. This works for me:
func2 = @(x,y) (50 + x .* cos(y)) .^ 3 .* (50 + x .* sin(y)) + (50 + x .* cos(y)) .*(50 + x .* sin(y)) .^2 ;
That's all. Common mistake :)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by