why result is zero?

4 visualizaciones (últimos 30 días)
Habib
Habib el 10 de Mzo. de 2015
Comentada: Torsten el 10 de Mzo. de 2015
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 comentarios
Habib
Habib el 10 de Mzo. de 2015
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 el 10 de Mzo. de 2015
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.

Iniciar sesión para comentar.

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by