Symbolic function Gaussian Beam
Afficher commentaires plus anciens
Actually I want to plot the intensity profile I(x,y,z,lambda,wo) of a gaussian beam. Some how I get confused with handle @(x,y..) and syms. May some one help.
r = @(x,y) sqrt(x^2+y^2); % Distance
k = @(lambda) 2*pi*lambda; % Wavenumber
w = @(w0,z,z0) w0*sqrt(1+(z/z0)^2); % Beamradius
R = @(z,z0) z*(1+(z0/z)^2); %
w0= @(lambda,z0) sqrt(lambda*z0/pi);
z0= @(w0, lambda) pi*w0^2/lambda;
xi= @(z, z0) atan(z/z0);
E = @(x,y,z,E0) ...
E0*w0(1,1) / w(1,z,z0(1,1))...
* exp(-(r(x,y)/w(w0,z,z0(1,1)))^2) ...
* exp(-1i*k(1)*z-xi(z, z0(1,1))) ...
* exp(-1i*k(1)*r(x,y)^2/2/R(z,z0(1,1)));
I=@(x,z) E(x,1,z,1)^2;
figure()
fcontour(I)
Réponses (2)
Star Strider
le 9 Nov 2023
Modifié(e) : Star Strider
le 9 Nov 2023
0 votes
You need to use element-wise operations. See the documentation on Array vs. Matrix Operations for details.
For example, ‘R’ becomes:
R = @(z,z0) z.*(1+(z0./z).^2);
Addition, subtraction, and multiplication of an array by a scalar are element-wise by definition.
.
1 commentaire
De Le
le 10 Nov 2023
w0 and z0 are function handles. You can't use them like variables in your definitions.
Further, E is a complex-valued function. fcontour can only plot real-valued functions.
2 commentaires
De Le
le 10 Nov 2023
lambda = 1;
w0 =1;
E0 =1;
z0 = pi*w0^2/lambda;
k = 2*pi*lambda; % Wavenumber
r = @(x,y)sqrt(x.^2+y.^2); % Distance
w = @(z)w0*sqrt(1+(z/z0).^2); % Beamradius
R = @(z) z.*(1+(z0./z).^2); %
xi = @(z)atan(z/z0);
E = @(x,y,z)...
E0*w0 ./ w(z)...
.* exp(-(r(x,y)./w(z)).^2) ...
.* exp(-1i*k*z-xi(z)) ...
.* exp(-1i*k*r(x,y).^2./2./R(z));
I = @(x,z)E(x,1,z).*conj(E(x,1,z));
fcontour(I,[-4 4 -30 1],'Fill','on' )
colorbar
Catégories
En savoir plus sur Parametric Modeling dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

