Учитывая два параметризованных отрезка, как можно выполнить двойную интеграцию вдоль них?
Вот что я пытаюсь сделать:
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