How to create an array?

조회 수: 3 (최근 30일)
Vaswati Biswas
Vaswati Biswas 2021년 11월 10일
편집: Rena Berman 2021년 11월 19일
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
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])
Rena Berman
Rena Berman 2021년 11월 19일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
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.
  댓글 수: 1
Vaswati Biswas
Vaswati Biswas 2021년 11월 11일
Thanks this helps me

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by