How to create an array?
2 ビュー (過去 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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!