我需要以八度为单位进行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
答案 0 :(得分:0)
我认为问题在于您对integral3
的调用中的限制定义:
integral3( @(y, phi, theta) f3(x, y, phi, theta), p5, p6, @(x,y) p3(x,y), @(x,y) p4(x,y), p1, p2)
您正在尝试将y
到phi
,theta
到{{1}的p5
,p6
和p3(x,y)
中集成}和p4(x,y)
至p1
。 p2
允许使用函数值限制,但only in a very specific way:
integrate3
这实际上反映了整合将如何在纸上进行。所以你拥有的是:
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
通过将限制定义为单值函数,我们基本上curry您的integral3(@(y, phi, theta) f3(x, y, phi, theta), p5, p6, @(y) p3(x,y), @(y) p4(x,y), p1, p2)
和p3
函数具有依赖于p4
积分变量的单值函数