Calculating the Integral over n ball ( Please Help )

2 ビュー (過去 30 日間)
A.M
A.M 2020 年 4 月 30 日
編集済み: Matt J 2020 年 4 月 30 日
Hello ,
I am tying to write a code to calculate the value of the integral over n-ball in any dimesion n of Euclidean space using symbolic integration in (hyper)spherical coordinates
but i am confused how can i do the last part of my code and is that possiable to do it with only one loop ?
this is my code :
% multiple integrals
fun={ @(r) 1, @(r) r, @(r) exp(-r), @(r) exp(-r^2) };
R=[1 1 2 3];
results = [ 0 3.1416 4.1888 4.9348 5.2638 5.1677
0 2.0944 3.1416 3.9478 4.3865 4.4295;
0 3.7322 8.1260 16.9216 33.2585 61.6291;
0 3.1412 5.5659 9.8574 17.4419 30.8130];
for k=1:4
for n=2:6
Int(n)=multint(n,R(k),fun{k});
end
Int
if all(round(Int,4)==results(k,:))
disp(['Case ',num2str(k),': result is correct!'])
else
disp(['Case ',num2str(k),': something is wrong!'])
end
end
return
function Int=multint(n,R,fun)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input: n...dimension of Euclidean space En (double), n>=2 %
% R...radius of n-ball Bn in En (double), R>0 %
% fun...handle of function fun(r) to be integrated over Bn %
%---------------------------------------------------------------------%
% Output: Int...value of the integral (double) %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check validity of input
Int=NaN;
if ~isreal(n) | n~=round(n) | n<2
warning('input n not valid, return NaN')
return
end
if ~isreal(R) | R<=0
warning('input R not valid, return NaN')
return
end
if ~isa(fun,'function_handle')
warning('input R not valid, return NaN')
return
end
%
% I need to write my function here
%
return
end
  1 件のコメント
darova
darova 2020 年 4 月 30 日
How fast should it be done? How urget is it?

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by