why I got zero answer?
7 次查看(过去 30 天)
显示 更早的评论
Hi everyone.
In below codes I used the trapz command for integration of u1_1, but answer is zero, what is wrong? And if I want to integrate respect to "r", what must I do?
clc
clear all
close all
a=3e-2;
z=0.42;
N=300;
lambda=1030e-9;
k=2*pi/lambda;
w0=0.0001;
zr=pi*w0^2/lambda;
R=z*(1+(zr/z)^2);
w=w0*sqrt(1+(z/zr)^2);
[x,y]=meshgrid(linspace(-a/2,a/2,N));
[teta,r] = cart2pol(x,y);
for i=1:N
for j=1:N
u1_1(i,j)=(r(i,j)./w).^2.*exp(-(r(i,j).^2)./w.^2);
end
end
for i=1:N
for j=1:N
u2(i,j)=trapz(u1_1(i,j));
end
end
0 个评论
回答(3 个)
Erik S.
2015-2-18
Hi
You do the integration in the loop with only 1 value at the time, so the integral should be 0. You should pass vectors to the trapz function. Do you want to do a double integral? Or integrate each row in the matrix u1_1?
Erik S.
2015-2-19
Hi again,
I'm not sure I understand your problem. But I send a new file, is it the result you need?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!