double integral in MATLAB, limits as variable?

36 visualizaciones (últimos 30 días)
Amit Kumar
Amit Kumar el 20 de Nov. de 2013
Comentada: Walter Roberson el 17 de Jun. de 2023
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?

Respuestas (2)

madhan ravi
madhan ravi el 6 de Jul. de 2018
Editada: Walter Roberson el 17 de Jun. de 2023
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 comentario
Walter Roberson
Walter Roberson el 17 de Jun. de 2023
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)

Iniciar sesión para comentar.


Hussein Thary
Hussein Thary el 17 de Jun. de 2023
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 comentario
Walter Roberson
Walter Roberson el 17 de Jun. de 2023
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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by