I can not say wether Eigs is giving expected results or not
Show older comments
Hello,
I am building a little mode solver for optical fibers based on this article : "Jesper Riishede et al 2003 J. Opt. A: Pure Appl. Opt. 5 534". As explained in the article I need to get the eigenvalues and eigenvectors of my matrix Phi. Since it is a large sized one I turned Phi into a sparse matrix and used eigs on it. But when I compute a simple "Phi*eigenvectors-eigenvectors*eigenvalues" I do not get small values <<1. The flag says eigs converged toward the solution without issue? I know based on what I expect to get from the simulation that the result is completely false but I do not know yet what to blame in my code.
So here is my question : Is there a scaling factor in the Phi*eigenvectors-eigenvectors*eigenvalues based on how big the initial values were, and eigs indeed converged or did it simply failed to reach an accurate solution? Or is there another issue?
Here is a sample of my code (the loop does not make sense but I had to break it to look for where I might have gone wrong a little bit faster since it fails on every iteration).
%%Function topology for DCF design
format long
%%Define the space for the study-----------------------------------
sizeX=25e-6;
sizeY=25e-6;
l=100;
m=100;
d=sizeX/l;
x=-sizeX/2:d:sizeX/2;
y=-sizeY/2:d:sizeY/2;
[xx,yy]=meshgrid(x,y);
n=zeros(size(xx));
Phi=zeros(m*l);
dPhi=sizeX/(l*m);
xX=-sizeX/2:dPhi:sizeX/2;
yY=-sizeY/2:dPhi:sizeY/2;
%%%%%%%%%%%%%%%%%%%%%%%%Iterate over 3 wl%%%%%%%%%%%%%%%%%%%%%%%%%%
%Basic physical parameters-----------------------------------------
A=readmatrix("C:\Users\Tessonneau Hugo\Desktop\Sellmeier Du goat2.txt");
lambdac=1030e-9;
dlambda=0.5e-9;
rcoreIni=5e-6;
rclad=125e-6;
nbg=1;
neff=[];
lambdac0=1535e-9;
lambdacmax=1575e-9;
for lambda0=lambdac0:5e-9:lambdac0%lambdac-dlambda:dlambda:lambdac+dlambda
n_SiO2=interp1(A(:,1)*1e-9,A(:,9),lambda0,'spline');
k0=2*pi/lambda0;
lambda0
%Initial design guess----------------------------------------------
nmin=n_SiO2;
nmax=sqrt(0.14^2+n_SiO2^2);
gammaicore=1;
gammaiclad=0.25;
% nicore=nmin+gammaicore*(nmax-nmin);
% niclad=nmin+gammaiclad*(nmax-nmin);
nicore=n_SiO2+0.38;
niclad=n_SiO2;
n=n*0+nbg;
n(xx.^2+yy.^2<rclad^2)=niclad;
n(xx.^2+yy.^2<rcoreIni^2)=nicore;
% figure(1);
% surf(xx,yy,n,'EdgeColor','none')
%Define Phi based on Helmoltz equation---------------------------------
% N=zeros(size(Phi));
for ii=1:1:l*m
for jj=1:1:l*m
% N(ii,jj)=n(floor(ii/l)+1,floor(jj/m)+1);
if(ii==jj)
Phi(ii,jj)=-4/dPhi^2+n(floor(ii/l)+1,floor(jj/m)+1)^2*k0^2;
elseif(ii==jj+1 || ii==jj-1 || jj==ii-1 || jj==ii+1)
Phi(ii,jj)=1/dPhi^2;
end
end
end
%%Eigenvalues calc--------------------------------------------------
Atest=sparse(rand(l*m));
Phi=sparse(Phi);
[eigenvector,eigenvalues,flag]=eigs(Phi,100,'largestabs','MaxIterations',1000000);
beta2=diag(eigenvalues);
Psi=eigenvector;
neff=[neff sqrt(beta2)./k0];
end
Thanks!
3 Comments
the cyclist
on 4 Sep 2025
Can you upload the input file Sellmeier Du goat2.txt so that we can run your code?
Torsten
on 4 Sep 2025
The matrix A is missing.
Where do you test
Phi*eigenvectors-eigenvectors*eigenvalues = 0
in your code ?
Hugo
on 4 Sep 2025
Accepted Answer
More Answers (0)
Categories
Find more on Linear Algebra 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!