필터 지우기
필터 지우기

I have a problem in my code. Who can help me to fix it?.. I can't find my mistake. Please help me.

조회 수: 2 (최근 30일)
close; clear; clc;
lambda = 532e-9; % laser Nd:Yag wavelength second harmonic
k = 2 .*pi ./lambda;
w0 = 0.01; % Laser radius
z = 5000; %.* (0.01:0.005:1); % 5 km distance
[x,y] = meshgrid((-1:0.01:1).*0.5);
[phi,r] = cart2pol(x,y); % Changing the polar coordinate variable to Cartesian
z_R = k .*w0 .^2 ./2; % Constant
w = w0 .*sqrt(1 + (z./z_R) .^2); % Constant
R = z_R .*(z./z_R + z_R./z); % Constant
l = 1; % l = ..., -3, -2, -1, 0, 1, 2, 3, ...
p = 2; % p = 0, 1, 2, 3, ...
N = abs(l) + 2 .*p;
Clp = sqrt(2 .*factorial(p) ./(pi .*factorial(p + abs(l)))); % clp is a parameter in laguerre gaussian beam equation that you can see in " https://en.wikipedia.org/wiki/Gaussian_beam "
% This below laguerre0-3 is lagurre polynomials that you can see in " https://en.wikipedia.org/wiki/Laguerre_polynomials "
laguerre0 = '@(A,l) 1';
laguerre1 = '@(A,l) -A + l + 1';
laguerre2 = '@(A,l) A.^2 ./2 - (l + 2) .*A + (l + 1) .*(l + 2) ./2';
laguerre3 = '@(A,l) -1 .*A.^3 ./6 + (l + 3) .*A.^2 ./2 - (l + 2) .*(l +3) .*A ./2 + (l + 1) .*(l + 2) .*(l+3) ./6';
fun = str2func("laguerre" + num2str(p));
% u is laguerre-gaussian equation you can see in " https://en.wikipedia.org/wiki/Gaussian_beam "
u = Clp ./w .*(sqrt(2 .*(x.^2 + y.^2)) ./w) .^abs(l) .*exp(-1 .*(x.^2 + y.^2) ./w .^2) ...
.*fun(2 .*(x.^2 + y.^2) ./w.^2,l) .*exp(-1i .*k .*(x.^2 + y.^2) ./(2 .*R)) ...
.*exp(1i .*l .*phi) .*exp(1i .*(N + 1) .*atan(z ./z_R));
I = abs(u).^2;
s=pcolor(x,y,I);
s.EdgeColor = "none";

채택된 답변

Stephen23
Stephen23 2023년 11월 10일
편집: Stephen23 2023년 11월 10일
Rather than forcing pseudo-indices into variable names and then attempting to use STR2FUNC.... simply use a cell array:
lambda = 532e-9; % laser Nd:Yag wavelength second harmonic
k = 2 .*pi ./lambda;
w0 = 0.01; % Laser radius
z = 5000; %.* (0.01:0.005:1); % 5 km distance
[x,y] = meshgrid((-1:0.01:1).*0.5);
[phi,r] = cart2pol(x,y); % Changing the polar coordinate variable to Cartesian
z_R = k .*w0 .^2 ./2; % Constant
w = w0 .*sqrt(1 + (z./z_R) .^2); % Constant
R = z_R .*(z./z_R + z_R./z); % Constant
l = 1; % l = ..., -3, -2, -1, 0, 1, 2, 3, ...
p = 2; % p = 0, 1, 2, 3, ...
N = abs(l) + 2 .*p;
Clp = sqrt(2 .*factorial(p) ./(pi .*factorial(p + abs(l)))); % clp is a parameter in laguerre gaussian beam equation that you can see in " https://en.wikipedia.org/wiki/Gaussian_beam "
% This below laguerre0-3 is lagurre polynomials that you can see in " https://en.wikipedia.org/wiki/Laguerre_polynomials "
laguerre = {...
@(A,l) 1,...
@(A,l) -A + l + 1,...
@(A,l) A.^2 ./2 - (l + 2) .*A + (l + 1) .*(l + 2) ./2,...
@(A,l) -1 .*A.^3 ./6 + (l + 3) .*A.^2 ./2 - (l + 2) .*(l +3) .*A ./2 + (l + 1) .*(l + 2) .*(l+3) ./6};
fun = laguerre{p+1};
% u is laguerre-gaussian equation you can see in " https://en.wikipedia.org/wiki/Gaussian_beam "
u = Clp ./w .*(sqrt(2 .*(x.^2 + y.^2)) ./w) .^abs(l) .*exp(-1 .*(x.^2 + y.^2) ./w .^2) ...
.*fun(2 .*(x.^2 + y.^2) ./w.^2,l) .*exp(-1i .*k .*(x.^2 + y.^2) ./(2 .*R)) ...
.*exp(1i .*l .*phi) .*exp(1i .*(N + 1) .*atan(z ./z_R));
I = abs(u).^2;
s = pcolor(x,y,I);
s.EdgeColor = "none";
  댓글 수: 4
Babr
Babr 2023년 11월 10일
just, in line 20 " fun = laguerre{p+1} "
This way it becomes more complete.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by