double integral in MATLAB, limits as variable?

조회 수: 35 (최근 30일)
Amit Kumar
Amit Kumar 2013년 11월 20일
댓글: Walter Roberson 2023년 6월 17일
Hi, Is it possible to do a double integral in MATLAB numerically, where limits are functions of variables?
Say my integrand is
x*y dy * dx
limits are
y=0 to 5x
x = 0 to 5
I can manage this by
syms x y
double(int(int(x*y,y,0,5*x),x,0,5))
But, I think, this is clumsy way. This will get worse for triple integrals. Is there any direct function where we can put limits directly with limits even including variables?

답변 (2개)

madhan ravi
madhan ravi 2018년 7월 6일
편집: Walter Roberson 2023년 6월 17일
fun = @(x,y) x.*y;
xmin = 0;
xmax = 5;
ymin = 0;
ymax = @(x) 5*x;
Q = integral2(fun,xmin,xmax,ymin,ymax,'Method','tiled')
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 6월 17일
Note that when you use integral2() that the first two limits must be numeric. The third and fourth limits may be either numeric or a function handle with a single parameter. The first two limits apply to the first variable of integration and the third and fourth limits apply to the second variable of integration.
Thus, @madhan ravi has correctly shown an integral2() in which the second variable of integration, y, has an upper bound that is defined by a function handle in terms of the first variable of integration.
If you had a case where the limit on x was defined in terms of y, then y would have to be the first variable of integration, and you would have to be careful about the order of parameters.
integral2(@(FullyIndependent,PartlyDependent) fun(PartlyDependent,FullyIndependent), FullyLower, FullyUpper, PartlyLower, PartlyUpper)

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


Hussein Thary
Hussein Thary 2023년 6월 17일
inte
R=1.33e3;no=1;D=2.28e3;L=1330 ;Wo=1e-3
lamda=514.5e-9;k=2*pi/lamda;alfa=1;
f=@(r, fai)exp(-alfa*L./2).*exp(-j*k*r*theata*cos(fai)).*exp((-r^2./w^2)-(j*fai));
f1=Ao.*f;
s=(abs(integral(f1,0,inf,0,2*pi))^2.*(abs(1/j*lamda))^2
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
plot(r,s)
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 6월 17일
s=(abs(integral(f1,0,inf,0,2*pi))^2.*(abs(1/j*lamda))^2
% 1 2 3 21 2 3 21
Each number indicates the number of levels of open brackets in effect "after" the character above is processed.
So you have 1 open bracket in effect at the end of the line. You should have zero open brackets at the end of the expression.

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

카테고리

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