How to create an array?
1 次查看(过去 30 天)
显示 更早的评论
I want to calculate the value of S by varying the hf but it only gives me a point. My code is given below. Kindly help
clc
clearvars
close all
nf=2.1511;
ns=1.5157;
nc=1.3279;
rho=1;
lambda = 532.3;
m= 0;
NEFF = [];
S= [];
syms neff
%NEFF = zeros(size(hf));
for hf=linspace(100,130,5)
NEFF = zeros(size(hf));
phi_c = -atan((nf/nc)^(2*rho)*sqrt ((neff.^2-nc^2)/(nf^2-neff.^2)));
phi_s = -atan((nf/ns)^(2*rho)*sqrt ((neff.^2-ns^2)/(nf^2-neff.^2)));
Eqn = ((((2*pi./lambda)*(sqrt(nf^2-neff.^2)*hf))+(-atan((nf/nc).^(2*rho)*sqrt ((neff.^2-nc^2)/(nf^2-neff.^2))))+ (-atan((nf/ns).^(2*rho)*sqrt ((neff.^2-ns^2)/(nf^2-neff.^2)))) -(m*pi)))==0;
assume(neff>0)
NEFF= vpasolve(Eqn, neff, [0, 5]);
%NEFF(ii)= abs(NEFF1(ii));
deltaz_c = (lambda./2*pi).*(NEFF.^2-nc^2).^(-0.5).*((NEFF./nf).^2+(NEFF./(nc.^2)-1)).^(-rho);
deltaz_s = (lambda./2*pi).*(NEFF.^2-ns^2).^(-0.5).*((NEFF./nf).^2+(NEFF./(ns.^2)-1)).^(-rho);
heff = deltaz_c+ deltaz_s+hf;
P_c = ((nf.^2-NEFF.^2)./(nf^2-nc^2)).*(deltaz_c./heff);
S = (NEFF./nc).* P_c.*((2*(NEFF./nc).^2)-1).^rho;
end
plot(hf, S, 'b-d', 'DisplayName', 'neff: imag part'), hold on
%xlim([850 1850])
2 个评论
Cris LaPierre
2021-11-11
I want to calculate the value of S by varying the hf but it only gives me a point. My code is given below. Kindly help
clc
clearvars
close all
nf=2.1511;
ns=1.5157;
nc=1.3279;
rho=1;
lambda = 532.3;
m= 0;
NEFF = [];
S= [];
syms neff
%NEFF = zeros(size(hf));
for hf=linspace(100,130,5)
NEFF = zeros(size(hf));
phi_c = -atan((nf/nc)^(2*rho)*sqrt ((neff.^2-nc^2)/(nf^2-neff.^2)));
phi_s = -atan((nf/ns)^(2*rho)*sqrt ((neff.^2-ns^2)/(nf^2-neff.^2)));
Eqn = ((((2*pi./lambda)*(sqrt(nf^2-neff.^2)*hf))+(-atan((nf/nc).^(2*rho)*sqrt ((neff.^2-nc^2)/(nf^2-neff.^2))))+ (-atan((nf/ns).^(2*rho)*sqrt ((neff.^2-ns^2)/(nf^2-neff.^2)))) -(m*pi)))==0;
assume(neff>0)
NEFF= vpasolve(Eqn, neff, [0, 5]);
%NEFF(ii)= abs(NEFF1(ii));
deltaz_c = (lambda./2*pi).*(NEFF.^2-nc^2).^(-0.5).*((NEFF./nf).^2+(NEFF./(nc.^2)-1)).^(-rho);
deltaz_s = (lambda./2*pi).*(NEFF.^2-ns^2).^(-0.5).*((NEFF./nf).^2+(NEFF./(ns.^2)-1)).^(-rho);
heff = deltaz_c+ deltaz_s+hf;
P_c = ((nf.^2-NEFF.^2)./(nf^2-nc^2)).*(deltaz_c./heff);
S = (NEFF./nc).* P_c.*((2*(NEFF./nc).^2)-1).^rho;
end
plot(hf, S, 'b-d', 'DisplayName', 'neff: imag part'), hold on
%xlim([850 1850])
采纳的回答
Cris LaPierre
2021-11-10
See the examples on the for loop documentation page. You can also learn how to do this interactively in Ch 12 of MATLAB Onramp.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!