필터 지우기
필터 지우기

integral2 error, bu the function works

조회 수: 2 (최근 30일)
Xiangyu Meng
Xiangyu Meng 2017년 2월 10일
답변: Carlos Guerrero García 2022년 11월 26일
fun = @(x,y) 1-exp(-0.01*norm(x-y));
q = integral2(fun,0,1,0,1);
It gives me the following error:
Error using integral2Calc>integral2t/tensor (line 241)
Integrand output size does not match the input size.
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);
Error in IntegrateTriangularRegionwithSingularityattheBoundaryExample (line 19)
q = integral2(fun,0,1,0,ymax)
The function fun is well defined and tested. Work for both scalar and vector.
How to make the integral work?
[SL: edited to format code]

답변 (2개)

Steven Lord
Steven Lord 2017년 2월 10일
What does the integral2 function require of the integrand function you specify as its first input?
"The function fun must accept two arrays of the same size and return an array of corresponding values. It must perform element-wise operations."
What does your function do?
fun = @(x,y) 1-exp(-0.01*norm(x-y));
x = 1:10;
y = x+1;
z = fun(x, y)
Is z the same size as x and y? I think something closer to what you want is:
fun = @(x,y) 1-exp(-0.01*abs(x-y));
x = 1:10;
y = x+1;
z = fun(x, y)
  댓글 수: 2
Xiangyu Meng
Xiangyu Meng 2017년 2월 10일
I want to calculate the integral of the function fun in the planar [0,1]*[0,1].
Torsten
Torsten 2017년 2월 13일
As Steven suggested, replace "norm" with "abs" in your function definition.
Best wishes
Torsten.

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


Carlos Guerrero García
Carlos Guerrero García 2022년 11월 26일
A sketch of the function:
[x,y]=meshgrid(0:0.01:1); % The region in the statement
surf(x,y,1-exp(-0.01*abs(x-y))); % Plotting the surface
shading interp % For a nice view
and the integral can be calculated as follows:
syms x y; int(int(1-exp(-0.01*abs(x-y)),0,1),0,1)
ans = 

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by