필터 지우기
필터 지우기

Plot 3D figure

조회 수: 2 (최근 30일)
Tina Hsiao
Tina Hsiao 2021년 11월 11일
댓글: Walter Roberson 2021년 11월 12일
Hello, I would like to plot this fugure (ro, Z, I), my code as below, could you please give me a help? Thanks a lot.
clear all; close all; clc
for n = 1:1:100
i = sqrt(-1);
a = 0.62;
NA = 0.29;
wL = 772e-3; % micro meter
R = linspace (-0.4,0.4,100);
ro = ((2*pi)/wL)*NA.*R;
Z = linspace(-1,1,100);
mu = ((2*pi)/wL)*NA^2*Z;
fun1 = @(r)r.*exp(-r.^2).* besselj(ro(n),r) .*exp(-(1.*i.*mu(n).*r.^2)./2);
q1 = integral(fun1,0,1);
q2 = integral(fun1,0,a);
E(n) = (2/(1-exp(-1)))*q1- 2*(2/(1-exp(-1)))*q2; % electric field
I(n) = abs(E(n)).^2; % intensity
end
figure(2)
plot(R, I)

채택된 답변

Walter Roberson
Walter Roberson 2021년 11월 11일
The scale factor between and Z or R values is not obvious. It is also not obvious why you used the ranges you did: the sample plot suggests that they should be reversed. However, I had to use those ranges to get any plot of note -- and you can see it is not the expected plot. The output was essentially unchanged with Z -- which suggests that possibly Z is the wrong scale.
a = 0.62;
NA = 0.29;
wL = 772e-3; % micro meter
num_R = 100;
num_Z = 101;
Zvals = linspace(-5,5,num_Z)/1e2;
Rvals = linspace(-40,40,num_R)/1e2;
for Ridx = 1 : num_R
R = Rvals(Ridx);
ro = ((2*pi)/wL)*NA.*R;
for Zidx = 1 : num_Z
Z = Zvals(Zidx);
mu = ((2*pi)/wL)*NA^2*Z;
fun1 = @(r)r .* exp(-r.^2) .* besselj(ro,r) .* exp(-(1.*i.*mu.*r.^2)./2);
q1 = integral(fun1,0,1);
q2 = integral(fun1,0,a);
E(Ridx, Zidx) = (2/(1-exp(-1)))*q1 - 2*(2/(1-exp(-1)))*q2; % electric field
end
end
I = abs(E).^2; % intensity
figure(2)
surf(Zvals, Rvals, I, 'edgecolor', 'none')
  댓글 수: 2
Tina Hsiao
Tina Hsiao 2021년 11월 12일
Thanks a lot. It works.
clear all; close all; clc
NA = 0.29;
wL = 772e-3; % micro meter
num_Z = 100;
num_R = 100;
Zvals= linspace(-40,40,num_Z);
Rvals = linspace(-5,5,num_R);
for Zidx = 1 : num_Z
Z = (Zvals(Zidx));
mu = ((2*pi)/wL).*NA^2.*Z;
for Ridx = 1 : num_R
R = (Rvals(Ridx));
ro = ((2*pi)/wL)*NA.*R;
fun1 = @(r)r.* exp(-r.^2) .* besselj(0,ro*r).* exp(-(1.*i.*mu.*r.^2)./2);
fun2 = @(a)a.* exp(-a.^2) .* besselj(0,ro*a).* exp(-(1.*i.*mu.*a.^2)./2);
q1 = integral(fun1,0,1);
q2 = integral(fun2,0,0.62);
E(Ridx, Zidx) = (2/(1-exp(-1))).*q1 - 2*(2/(1-exp(-1))).*q2; % electric field
end
end
phase = atan2(imag(E),real(E));
I = abs(E).^2; % intensity
figure(2)
surf( Rvals, Zvals, I/max(max(I)), 'edgecolor', 'none')
Walter Roberson
Walter Roberson 2021년 11월 12일
Looks good, but what do you do with phase after you calculate it?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by