Multidimensional integration in matlab

5 ビュー (過去 30 日間)
Shunan Sheng
Shunan Sheng 2021 年 4 月 13 日
コメント済み: Bjorn Gustavsson 2021 年 4 月 14 日
I would like to integrate a multivariate function such as
over . Is there a built in function in matlab to do this? Expanding it to a function of , the components of x will be really tedious if the dimension is higher.

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 4 月 13 日
Have a look at the help and documentation for integral2. That should be the function to do 2-D integrals, that sounds like the function you're looking for.
HTH
  2 件のコメント
Shunan Sheng
Shunan Sheng 2021 年 4 月 14 日
編集済み: Shunan Sheng 2021 年 4 月 14 日
Thanks, I tried the integral2, but there are some problems. Here is the code:
clear all;
A=diag(ones(2,1));
func = @(x, y)(quadratic_form(x, y, A));
integral_value = integral2(func, -1,1,-1,1);
function value = quadratic_form(x, y, A)
x=reshape(x,[],1);
y=reshape(y,[],1);
mat = [x,y];
disp(size(mat));
value = diag(mat * A * mat');
disp(size(value))
end
In particular, we have error
Error using integral2Calc>integral2t/tensor (line 241)
Integrand output size does not match the input size.
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 4 月 14 日
That is because your function is array-valued, and as far as I know integral2 doesn't handle that. You might have to evaluate the integral for each component separately.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by