Saving Data for Each for loop
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I tried this task several times but don't know why I'm not getting the expected results. Here in the code, I used a signle value for n1 and n2. As a result, I got single graph or single value for wave. If I have five values for n1 and n2 each (length of n1 and n2 will be always same), then I should get five graphs or five values for wave. I assume I have to use two for loops: one for n1 and n2, and another one for lam. Then for each n1 & n2 value, I will get a range for lam. In the code, I used B=n2*k:(n1*k-n2*k)./((length(lam))-1):n1*k; so that I can get B values same length (not values) to lam. If lam has 100 values for example, B will have 100 values. You are free to change the expression in B between n2*k and n1*k. B will have a range and the min and max value will be n2*k and n1*k, respectively. Thanks in advance.
clc; clear all; close all;
format long
m=1; p=0.5296; n3=1; a1=4.1*m; a2=62.5*m; dn=10^-3;
n1=1.44507;
n2=1.4444;
lam=1.51*m:0.0001*m:1.55*m;
NA=sqrt(n1^2-n2^2);
k=2*pi./lam;
B=n2*k:(n1*k-n2*k)./((length(lam))-1):n1*k;
neff=B./k;
V=(2*pi*a1*sqrt(n1^2-n2^2))./lam;
b=(neff.^2-n2^2)./(n1^2-n2^2);
%Bessels function
aa=V.*sqrt(1-b);
bb=V.*sqrt(b);
LHS=aa.*(besselj(1,aa)./besselj(0,aa));
RHS=bb.*(besselk(1,bb)./besselk(0,bb));
yc=LHS-RHS;
% core effective index
difference=abs(yc);
min_diff=min(difference);
intersect=find(difference==min_diff);
nc=neff(intersect);
% coupling coefficient
lam_fbg=1.530;
n=(pi^2*(2*a1)^2*NA^2)./(lam.^2+pi^2*(2*a1)^2*NA^2); % overlaping factor
kk=(pi.*n.*dn)./lam_fbg; % coupling coefficient
% detuning factor
L=3000;
d=(2*pi*nc./lam)-pi/p;
dk=d./kk; % detuning ratio
% Bragg normalized reflectivity
kl=kk.*L;
x1=sqrt(1-dk.^2);
x2=(sinh(kl.*x1)).^2;
x3=1-dk.^2;
x4=(cosh(kl.*x1)).^2;
x5=dk.^2;
R=x2./(x3.*x4+x5.*x2);
plot(lam,R);
[ymax, inx]=max(R);
wave=lam(inx);
4 commentaires
Réponses (1)
Gaurav Garg
le 25 Jan 2021
Hi Sohel,
The above function throws an error when we try to run it with n1 and n2 having 5 values.
The error displayed is -
Incorrect dimensions for raising a matrix to a power
0 commentaires
Voir également
Catégories
En savoir plus sur Sparse Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!