给出两个参数化的线段,一个线段如何沿它们进行双重积分?
这就是我想要做的:
p10 = [0,0,0]; %line 1 start
p11 = [1,1,1]; %line 1 end
p20 = [0,1,0]; %line 2 start
p21 = [1,0,0]; %line 2 end
p1 = @(t) transpose(t).*(p11-p10)+p10; % line 1 parametrization
p2 = @(t) transpose(t).*(p21-p20)+p20; % line 2 parametrization
r = @(t1,t2) vecnorm(p1(t1) - p2(t2), 2, 2); % distance between points in each line
k = 0.1 + 0.9j;
fun = @(t1,t2) exp(-k*r(t1,t2))./r(t1,t2);
integral2(fun, 0,1,0,1) % error: Matrix dimensions must agree.
完整的错误消息:
Matrix dimensions must agree. Error in @(t)transpose(t).*(p11-p10)+p10 Error in @(t1,t2)vecnorm(p1(t1)-p2(t2),2,2) Error in @(t1,t2)exp(-k*r(t1,t2))./r(t1,t2) Error in integral2Calc>integral2t/tensor (line 228) Z = FUN(X,Y); NFE = NFE + 1; Error in integral2Calc>integral2t (line 55) [Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT); Error in integral2Calc (line 9) [q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct); Error in integral2 (line 106) Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
根据错误消息,matlab必须将长度不匹配的参数传递给fun
。即length(t1) != length(t2)
。我该如何避免呢?
注意:这种行为是意外的,因为在integral2
的描述中有:
All input functions must accept arrays as input and operate elementwise. The function Z = FUN(X,Y) must accept arrays X and Y of the same size and return an array of corresponding values. The functions YMIN(X) and YMAX(X) must accept arrays and return arrays of the same size with corresponding values.
以下代码不会引发错误
t1 = 0:0.1:1;
t2 = t1 + 1;
fun(t1,t2); % no error