确定的八度 4D 积分,以功能为限制

definite 4D integration in octave, with functions as limits

我需要在 Octave 中进行 4D 积分。 我的函数是 f(x,y,phi,theta),一些积分限制是外部限制的函数。

0 < theta < pi
t1(x,y) < phi < t2(x,y)
h1 < y < h2
w1 < x < w2

我是这样用八度写的(概括):

[q1(i)] = integral( @(x) (integral3( @(y, phi, theta) f3(x, y, phi, theta), h1 , h2 , @(x,y) t1(x,y), @(x,y) t2(x,y), 0, pi)), w1, w2, 'ArrayValued',true);

我的实际代码:

clear all;
clc;
rho_bulk = 2.44; # rho_bulk = 2.44 uOhm.cm
h = 20e-9;
p = 0.5;
lambda = 40e-9;
n = 10;
w = linspace(20e-9,80e-9,n);

  for i = 1:n
  # limit for theta
  p2    = pi;
  p1    = 0;

  # limit for phi
  p4    = @(x,y) atan(x/(h-y)) + (pi/2);
  p3    = @(x,y) -atan((h-y)/(w(i)-x));

  # limit for y
  p6    = h;
  p5    = 0;

  # limit for x
  p8(i) = w(i);
  p7    = 0;

  #   f(x, y, phi, theta); outer --> inner
  #   limits;              inner --> outer

  f1 = @(x, y, phi, theta) exp(-(h-y)/(lambda *sin(theta) *sin(phi)));  
  f3 = @(x, y, phi, theta) sin(theta).*cos(theta).^2 .* f1(x, y, phi, theta);

  [q1(i)] = integral( @(x) (integral3( @(y, phi, theta) f3(x, y, phi, theta), p5, p6, @(x,y) p3(x,y), @(x,y) p4(x,y), p1, p2)), p7, p8(i), 'ArrayValued',true);

我的积分线有错误

error: 'y' undefined near line 51 column 98

我通过以下这些了解了集成:

https://www.mathworks.com/matlabcentral/answers/77571-how-to-perform-4d-integral-in-matlab

Quadruple Integral Using Nested Integral2 in Matlab

我认为问题出在您对 integral3:

调用中限制的定义中
integral3( @(y, phi, theta) f3(x, y, phi, theta), p5, p6, @(x,y) p3(x,y), @(x,y) p4(x,y), p1, p2)

您正在尝试整合 yphitheta,从 p5p6p3(x,y)p4(x,y)p1p2integrate3 允许函数值限制,但是 only in a very specific way:

q = integral3 (f, xa, xb, ya, yb, za, zb, prop, val, …)

    Numerically evaluate the three-dimensional integral of f using adaptive quadrature
    over the three-dimensional domain defined by xa,
    xb, ya, yb, za, zb (scalars may be finite or infinite). Additionally,
    ya and yb may be scalar functions of x and za, and zb maybe be scalar
    functions of x and y, allowing for integration over non-rectangular
    domains.

这实际上反映了集成在纸面上的工作方式。所以你拥有的是:

p5, p6,
@(x,y) p3(x,y), @(x,y) p4(x,y),
p1, p2

你的第二个限制试图依赖于两个变量,而它们可能只依赖于一个:第一个积分变量。但这很好,因为 x 不是积分变量,它只是一个参数。所以我相信以下应该有效:

integral3(@(y, phi, theta) f3(x, y, phi, theta), p5, p6, @(y) p3(x,y), @(y) p4(x,y), p1, p2)

通过将限制定义为单值函数,我们基本上 curry 您的 p3p4 函数具有依赖于 y 的单值函数积分变量。