Plot 3D figure

5 次查看(过去 30 天)
Tina Hsiao
Tina Hsiao 2021-11-11
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