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

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 件のコメント

Kobye
Kobye 2013 年 10 月 23 日
Also, maple can evaluate this integral numerically quite easily.

サインインしてコメントする。

回答 (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 :)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2013 年 10 月 23 日

回答済み:

2016 年 8 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by