필터 지우기
필터 지우기

A 4D Nested numerical integration

조회 수: 2 (최근 30일)
Taqu3
Taqu3 2022년 4월 22일
댓글: Torsten 2022년 4월 22일
Hello. I am new to matlab. I am trying to integrate a function over time and 3-space coordinate using vpaintegral command given below by the S12int1 command. I have waited tens of hours but did not get any result. When it is over 2D given by S12int2 I get the answer in few seconds. In 3D I get a result in about 10 minutes. I list my questions below. Any help is very much appreciated.
  1. What is the stragegy to evaluate multidimensional integrals in general ? Do you recommend vpaintegral over integrate command
  2. In vpaintegral command I can set the accuracy by setting for instance 'RelTol',1e-15,'AbsTol',1e-20. What I observed is if the integrand's magnitude is much larger than the value set by the tolerance values above, integration takes forever. Why is that so ? Do I need to adjust tolerance values in accordance with the integrand's magnitude ?
  3. When using nested vpaintegral commands Do I need to specify error tolerances for each vpaintegral command ? Or just for the inner most integral ? A related question is do I need to put the command 'ArrayValued',true in each nest ?
  4. Is there any other approach ? I am condering turning integrals into summations and perform them in nested for loops. Do you think this would increase the error ?
Thank you!
close all;
%clc;
clear all;
syms t
syms phi
syms z
syms r
tic
zr=1/100; omega=1/100; tau=1; c=1; E0=1/10; kg=2; phik=pi/4; thetak=pi/7;
S12(t,r,z,phi) = exp(-1i*c*kg*t+1i*kg*z*cos(thetak)+ 1i*kg*r*cos(phi-phik)*sin(thetak)) ...
*exp(-(t+z/c)^2/tau^2)*exp(-2*(t-z/c)^2/tau^2)*zr^3/(z^2+zr^2)^(3/2)*exp(-3*r^2*zr*omega/(2*c*(z^2+zr^2)))...
*cos((z/c-t)*omega+r^2*z*omega/(2*c*(z^2+zr^2))-atan(z/zr))*cos((z/c-t)*omega+r^2*z*omega/(2*c*(z^2+zr^2))-atan(z/zr)) ...
*cos((-z/c-t)*omega-r^2*z*omega/(2*c*(z^2+zr^2))+atan(z/zr))*r;
%S12int1= vpaintegral(vpaintegral(vpaintegral(vpaintegral(S12(t,r,z,phi),t,[-3,3]),z,[-10,10]),r,[0,5]),phi,[0,2*pi]);
S12int2= vpaintegral(vpaintegral(vpaintegral(S12(t,r,z,pi/3),t,[-3,3]),r,[0,10]),z,[-10,10],'ArrayValued',true);
S12int2
%double(S12(1,1,1,1))
timeElapsed = toc
  댓글 수: 5
Taqu3
Taqu3 2022년 4월 22일
Is there a tutorial on how to use the file you have linked above ? Btw, I have tried the following
close all;
%clc;
clear all;
zr=1/100; omega=1/100; tau=1; c=1; E0=1/10; kg=2; phik=pi/4; thetak=pi/7;
S12 = @(t,r,z,phi) exp(-1i.*c.*kg.*t+1i.*kg.*z.*cos(thetak)+ 1i.*kg.*r.*cos(phi-phik).*sin(thetak)) ...
.*exp(-(t+z/c).^2/tau.^2).*exp(-2.*(t-z/c).^2/tau.^2).*zr.^3/(z.^2+zr.^2).^(3/2).*exp(-3.*r.^2.*zr.*omega/(2.*c.*(z.^2+zr.^2)))...
.*cos((z/c-t).*omega+r.^2.*z.*omega/(2.*c.*(z.^2+zr.^2))-atan(z/zr)).*cos((z/c-t).*omega+r.^2.*z.*omega/(2.*c.*(z^.2+zr.^2))-atan(z/zr)) ...
.*cos((-z/c-t).*omega-r.^2.*z.*omega/(2.*c.*(z.^2+zr.^2))+atan(z/zr)).*r;
%integral(@(phi)arrayfun(@(phi)integral3(@(t,r,z)S12(t,r,z,phi),-10,10,0,5,-10,10),phi),0.01,3,'AbsTol',1e-20);
integral(@(phi)integral3(@(t,r,z)S12(t,r,z,phi),-10,10,0,5,-10,10),0,3,'ArrayValued',true,'AbsTol',1e-20)
Both of them gave the warning messages such as
Warning: Matrix is singular to working precision.
Arrays have incompatible sizes for this operation.
Torsten
Torsten 2022년 4월 22일
If you open integralN, you'll see some comments and examples from line 1 to line 75.
Start with simpler examples than yours to see how the code works.

댓글을 달려면 로그인하십시오.

답변 (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