How to create an array?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vaswati Biswas
am 10 Nov. 2021
Bearbeitet: Rena Berman
am 19 Nov. 2021
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 Kommentare
Cris LaPierre
am 11 Nov. 2021
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])
Akzeptierte Antwort
Cris LaPierre
am 10 Nov. 2021
See the examples on the for loop documentation page. You can also learn how to do this interactively in Ch 12 of MATLAB Onramp.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!