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