Compute double sum or double integral throug sum
6 次查看(过去 30 天)
显示 更早的评论
x=[-20:0.2:10];
y=[-10:0.2:5];
u2=-3*exp(-sqrt(x.^2+y.^2)/2)
I want to sum this function from y=1 to the number of elements of y vector then the sum of this result from x=1 to the number of elements in x. IT is actually a double integral in form of sum.
2 个评论
Adam
2017-10-30
You want to sum from y = 1 up to the number of elements in y even though y begins at -10 and runs to 5? How is that expected to work exactly?
采纳的回答
Honglei Chen
2017-10-30
If the ultimate goal is to compute the integral, you can consider using integral2
If you have to do it with sum, then since you already computed u2 for all values, it is just
x=[-20:0.2:10]; y=[-10:0.2:5]'; u2=-3*exp(-sqrt(x.^2+y.^2)/2);
sum(u2(:))*0.2*0.2
Note that you have to transpose x or y so it forms a grid
HTH
更多回答(1 个)
Roger Stafford
2017-10-30
[X,Y] = meshgrid(x,y);
M = -3*exp(-sqrt(X.^2+Y.^2)/2);
S = sum(M(:))*.2*.2; % The desired sum
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!