why result is zero?

4 次查看(过去 30 天)
Habib
Habib 2015-3-10
评论: Torsten 2015-3-10
Hi everybody. In second "for" nesting loop, I want to use Trapz command (numerical integration) for integration from an N*N matrix (u_2) but I got zero answer? What is wrong? I hope one give an answer.
clc
clear all
close all
aa=3e-2;
E0=10000;
z=0.42;
L=z;
N=100;
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);
D1=linspace(-aa/2,aa/2,N);
[x,y]=meshgrid(D1,D1);
b=(lambda*L)/(N*aa);
D2=linspace(-b/2,b/2,N);
[xx,yy]=meshgrid(D2,D2);
RR=1.5;
u1=ones(size(x));
u_2=u1;
u2=ones(size(xx));
[teta,r]=cart2pol(x,y);
[teta1,rr] = cart2pol(xx,yy);
for i=1:N
for j=1:N
u1(i,j)=E0*(r(i,j)/w)*exp(-(r(i,j)/w).^2);
end
end
for i=1:N
for j=1:N
u_2(i,j)=u1(i,j)*besselj(1,-k*r(i,j)*rr(i,j))*exp(-1i*k*rr(i,j)^2/(L*w^2))*cos(teta1(i,j));
u2(i,j)=trapz(u_2(i,j));
end
end
  2 个评论
Habib
Habib 2015-3-10
Thank you for your answer.
I read it, but i couldn't understand what is wrong. Now, what must I do? how i can fixed it?
Torsten
Torsten 2015-3-10
x = -3:.1:3;
y = -5:.1:5;
[X,Y] = meshgrid(x,y);
F = X.^2 + Y.^2;
I = trapz(y,trapz(x,F,2));
integrates the function f(x,y)=x^2+y^2 over the rectangle [-3:3]x[-5:5].
Now insert your function and your domain of integration.
Best wishes
Torsten.

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2015-3-10
Take a look at the chapter "Multiple numerical integrations" under
to see what is wrong with your call to trapz.
Best wishes
Torsten.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by