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 CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by