user defined function matrix dimensions must agree
Show older comments
Hi,
I have a problem with user defined functions for calculating the behaviour of tight focusing light based in the paper: Reverse and toroidal flux of light fields with both phase and polarization higher-order singularities in the sharp focus area (2019).
I created a function "A_theta" for the input field that I use in various other user defined functions called "I0_nu", "I1_nu", "I2_nu" etc. Function "A_theta" is the field amplitude multiplied by a pupil (binary mask) and I got the error message "Matrix dimensions must agree" for function "A_theta". I know the error is in the binary mask because when I ignore it I don't get the error message. I don't understand why I'm wrong if the pupil has the same size as the field function.
I attach the functions A_theta, I0_nu and a code where I employ them.
Thanks for your attention.
Carolina Rickenstorff
function y = A_theta(theta,k1,f,m,rho1,rho2,R,phi)
field=rho1.*besselj(m,k1.*rho1.*sin(theta))+rho2.*besselj(m,k1.*rho2.*sin(theta));
t1=f.*sin(theta).*cos(phi);
t2=f.*sin(theta).*sin(phi);
pupil=((t1.^2+t2.^2)<=R^2);
y=field.*pupil;
function y = I0_nu(theta,nu,z,r,k1,f,m,rho1,rho2,R,phi)
term = sin(theta).*sqrt(cos(theta)).*(1+cos(theta)).*exp(1i.*k1.*z.*cos(theta))...
.*besselj(nu,k1.*r.*sin(theta));
y=term.*A_theta(theta,k1,f,m,rho1,rho2,R,phi);
clear all
close all
clc
%w = warning('query','last')
id1='MATLAB:quadgk:MaxIntervalCountReached';
id2='MATLAB:quadgk:MinStepSize';
warning('off',id1)
warning('off',id2)
%%%Optical parameters
lambda=532e-9;
k=2*pi/lambda;
n1=1.518;
k1=n1.*k;
NA=1*n1;
f=0.01;
alfa=asin(NA/n1);
%%%%Pupil radius (m)
R=f.*sin(alfa);
%%%%Axis (m)
N=64;
x=linspace(-N/2,N/2-1,N);
x=2/N.*x.*1.25e-6;
x=repmat(x,N,1);
y=x';
phi=angle(x+1i.*y);
r=sqrt(x.^2+y.^2);
%%%%In tight focusing we use theta variable
theta=asin(r./f);
%%%%Vortex radii
rho1=0.00055.*R;
rho2=0.91.*rho1;
%%%%Topological charge, m=0 inclusive
m=0;
%%%%Polarization order, n=0 inclusive
n=0;
%%%%Integration order function I0_nu
nu=m+n;
%%%%Initializing
I0_nu1=zeros(N);
%%%%Focal point distance z=0
z=0;
for p=1:N*N
I0_nu1(p) =quadgk(@(theta)I0_nu(theta,nu,z,r(p),k1,f,m,rho1,rho2,R,phi),0,alfa);
if mod(p,8*N)==0;
%%%%Percentage tellboard
fprintf('completo %3.0f%%\n',round(p.*100./(N*N)))
end
end
Answers (1)
Carolina Rickenstorff
on 11 Mar 2020
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!