double integral in MATLAB, limits as variable?
9 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
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
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
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
plot(r,s)
1 个评论
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 Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!