代码中的步骤问题。需要帮助

时间:2017-04-09 09:08:59

标签: matlab plot

晚上好, 我的代码工作正常如下:

r=1.6;
M=0.000207;
D=-0.0256;
kappa=0.5;
gamma=20;%\W\km
Pp=0.2;
L=462.5;
SQ=sqrt(-(0.5*D)^2 +M);
z=0:0.1:L;
A=kappa*SQ.*(z-L);
B=((sqrt(M)/r)+(D/2))/(SQ);
C=EA(B);
E=SQ*cot(A+C);
Pminus=E-(D/2);
Pplus=M./Pminus;
P0=Pplus+Pminus+D;
CST1=Pplus.*Pminus;
CST2=P0-Pplus-Pminus;
dP0dz=kappa.*P0.*(Pplus-Pminus);
figure
set(gca,'fontsize',18)
plot(z,Pplus*1000, 'b',z,Pminus*1000,'r',z,P0*1000,'k','Linewidth',4);
xlabel('z(m)')
ylabel('Power (mW)')
legend('P_+','P_-','P_0','D','M','r','Orientation','horizontal')
%str = sprintf('D = %.4f , M = %.9f, and r =%.3f ',D,M,r);
%title(str);
xlim([0 L])
N=gamma.*Pp;%gamma Pp with units \km
y1=0.5*kappa.*1000*(Pplus+Pminus);
y2 =y1./N;
figure
hax=axes;
[ax,p1,p2] = plotyy(z,y1,z,y2,'plot','plot');
 set(ax,{'ycolor'},{'k';'k'}) 
set(ax,{'fontsize'},{18;18})
 set(p1,'linewidth',4)% to change the first line
 set(p2,'linewidth',4) % to change the second line
 set(p1,'Color','b')% to change the first line
 set(p2,'Color','b') % to change the second line
%str = sprintf('D = %.6f  ',D);
%title(str);
ylabel(ax(1),'K_{SBS}(km^{-1})','fontsize',18,...
 'Color','k') % label left y-axis
ylabel(ax(2),'K_{SBS}( \gamma P )','fontsize',18,...
'Color','k') % label right y-axis
xlabel(ax(2),'z(m)','fontsize',18,...
'Color','k')% label x-axis
set(ax(1),'XLim',[0 L])
set(ax(2),'XLim',[0 L])
set(ax(1),'YLim',[min(y1) max(y1)])
set(ax(2),'YLim',[min(y2) max(y2)])
zz1=(max(y1)-min(y1))./4;
zz2=(max(y2)-min(y2))./4;
set(ax(1),'YTick',min(y1):zz1: max(y1) )
set(ax(2),'YTick',min(y2):zz2: max(y2) )
legend('K_{SBS}(km^{-1})')
% figure
% set(gca,'fontsize',18)
% plot(z,1000*dP0dz,'Linewidth',4);
% xlabel('z(m)')
% ylabel('dP_0/dz')
% xlim([0 L])
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N=gamma.*Pp;%\km
lamdazero=1550;
lamdapump=linspace(1535,1560,100000);
lamdasignal=1545;
beta3=0.06;
beta4=-1*10^-4;
c=2*pi*299792458/1000;

A0=(1./lamdapump) -(1./lamdazero);
B0=(1./lamdapump) -(1./lamdasignal);

Third0=beta3.*(c.^3).*A0.*(B0.^2);
Fourth0=beta4.*(1./2).*c.^4.*(A0.^2).*(B0.^2);

Fourorder=c.^4.*beta4.*(1/12).*(B0).^4;
deltabeta=Third0+Fourth0+Fourorder;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%NO SBS
total0=deltabeta+(2.*N);
g0=((sqrt((N.^2)-(total0./2).^2)));
Gain0=((((N./(g0)).^2).*(sinh(g0.*L/1000)).^2));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
g0=1.1*10^-11;
Aeff=1.1*10^-11;
PSBS=0.016;
SBS=(g0.*PSBS.*1000)./Aeff; 
totalsbs=deltabeta+(2.*N)-SBS/2;
gsbs=((sqrt((N.^2)-(totalsbs./2).^2)));
Gainsbs=((((N./(gsbs)).^2).*(sinh(gsbs.*L/1000)).^2));
n=35;
first=round(1*(L/n));
step=round(L/n);
last=L;
 for jj=1:length(deltabeta)
 M = eye(2);
 for ii = first:step:last;
 tsv=deltabeta(jj)+(2*N)-(y1(z==(ii-round(0.5*(L/n)))));
 gsv=((sqrt((N.^2)-(tsv./2).^2)));
 F1=1i*tsv;
 F2=2*gsv;
 F3=F1./F2;
 F4=1i*(N./gsv);
 M1=cosh(gsv.*(step/1000))+(F3.*sinh(gsv.*(step/1000)));
 M2=F4.*sinh(gsv.*(step/1000));
 M3=-F4.*sinh(gsv.*(step/1000));
 M4=cosh(gsv.*(step/1000))-(F3.*sinh(gsv.*(step/1000)));
 M=M*[M1 M2;M3 M4];
 TeRm=P0(z==ii)/P0(z==(ii-step));
 M=[sqrt(TeRm) 0;0 1]*M;
 end
 Gv(1,jj)=M(1,1).*conj(M(1,1));
 end
FigHandle = figure;
figureh=plot(lamdapump,10*log10(1+Gain0),'b',lamdapump,10*log10(1+Gainsbs),'g',lamdapump,10*log10(Gv),'r','Linewidth',5);
hold on
xlabel('\lambda_P (nm)','Fontsize',18)
ylabel('Signal Gain (dB)','Fontsize',18)
legend('Without SBS',' With SBS ideal ',' With SBS actual')
% title('Gain curves with SBS','fontsize',18)
set(gca,'XTick',1536:3:1560)
set(gca,'fontsize',18)
ylim([0 12])
hold off

我的问题是,当将参数L更改为小于1的值时,如参数中的某些更改:

    r=1.8;
M=0.80322;
D=-1.69;
kappa=700/4.6;
gamma=5285;%\W\km
Pp=7.6;
L=0.045333;
SQ=sqrt(-(0.5*D)^2 +M);
z=0:0.00001:L;
A=kappa*SQ.*(z-L);
B=((sqrt(M)/r)+(D/2))/(SQ);
C=EA(B);
E=SQ*cot(A+C);
Pminus=E-(D/2);
Pplus=M./Pminus;
P0=Pplus+Pminus+D;
CST1=Pplus.*Pminus;
CST2=P0-Pplus-Pminus;
dP0dz=kappa.*P0.*(Pplus-Pminus);
figure
set(gca,'fontsize',18)
plot(z,Pplus*1000, 'b',z,Pminus*1000,'r',z,P0*1000,'k','Linewidth',4);
xlabel('z(m)')
ylabel('Power (mW)')
legend('P_+','P_-','P_0','D','M','r','Orientation','horizontal')
%str = sprintf('D = %.4f , M = %.9f, and r =%.3f ',D,M,r);
%title(str);
xlim([0 L])
N=gamma.*Pp;%gamma Pp with units \km
y1=0.5*kappa.*1000*(Pplus+Pminus);
y2 =y1./N;
figure
hax=axes;
[ax,p1,p2] = plotyy(z,y1,z,y2,'plot','plot');
 set(ax,{'ycolor'},{'k';'k'}) 
set(ax,{'fontsize'},{18;18})
 set(p1,'linewidth',4)% to change the first line
 set(p2,'linewidth',4) % to change the second line
 set(p1,'Color','b')% to change the first line
 set(p2,'Color','b') % to change the second line
%str = sprintf('D = %.6f  ',D);
%title(str);
ylabel(ax(1),'K_{SBS}(km^{-1})','fontsize',18,...
 'Color','k') % label left y-axis
ylabel(ax(2),'K_{SBS}( \gamma P )','fontsize',18,...
'Color','k') % label right y-axis
xlabel(ax(2),'z(m)','fontsize',18,...
'Color','k')% label x-axis
set(ax(1),'XLim',[0 L])
set(ax(2),'XLim',[0 L])
set(ax(1),'YLim',[min(y1) max(y1)])
set(ax(2),'YLim',[min(y2) max(y2)])
zz1=(max(y1)-min(y1))./4;
zz2=(max(y2)-min(y2))./4;
set(ax(1),'YTick',min(y1):zz1: max(y1) )
set(ax(2),'YTick',min(y2):zz2: max(y2) )
legend('K_{SBS}(km^{-1})')
% figure
% set(gca,'fontsize',18)
% plot(z,1000*dP0dz,'Linewidth',4);
% xlabel('z(m)')
% ylabel('dP_0/dz')
% xlim([0 L])
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N=gamma.*Pp;%\km
lamdazero=1556;
lamdapump=linspace(1300,1800,100000);
lamdasignal=1536;
beta3=1.26;
beta4=0;
c=2*pi*299792458/1000;

A0=(1./lamdapump) -(1./lamdazero);
B0=(1./lamdapump) -(1./lamdasignal);

Third0=beta3.*(c.^3).*A0.*(B0.^2);
Fourth0=beta4.*(1./2).*c.^4.*(A0.^2).*(B0.^2);

Fourorder=c.^4.*beta4.*(1/12).*(B0).^4;
deltabeta=Third0+Fourth0+Fourorder;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%NO SBS
total0=deltabeta+(2.*N);
g0=((sqrt((N.^2)-(total0./2).^2)));
Gain0=((((N./(g0)).^2).*(sinh(g0.*L/1000)).^2));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
g0=0.7*10^-9;
Aeff=2.3*10^-12;
PSBS=Pp*4/57.5;
SBS=(g0.*PSBS.*1000)./Aeff; 
totalsbs=deltabeta+(2.*N)-SBS/2;
gsbs=((sqrt((N.^2)-(totalsbs./2).^2)));
Gainsbs=((((N./(gsbs)).^2).*(sinh(gsbs.*L/1000)).^2));

n=35;
first=(1*(L/n));
step=(L/n);
last=L;
 for jj=1:length(deltabeta)
 M = eye(2);
 for ii = first:step:last;
 tsv=deltabeta(jj)+(2*N)-(y1(z==(ii-(0.5*(L/n)))));
 gsv=((sqrt((N.^2)-(tsv./2).^2)));
 F1=1i*tsv;
 F2=2*gsv;
 F3=F1./F2;
 F4=1i*(N./gsv);
 M1=cosh(gsv.*(step/1000))+(F3.*sinh(gsv.*(step/1000)));
 M2=F4.*sinh(gsv.*(step/1000));
 M3=-F4.*sinh(gsv.*(step/1000));
 M4=cosh(gsv.*(step/1000))-(F3.*sinh(gsv.*(step/1000)));
 M=M*[M1 M2;M3 M4];
 TeRm=P0(z==ii)/P0(z==(ii-step));
 M=[sqrt(TeRm) 0;0 1]*M;
 end
 Gv(1,jj)=M(1,1).*conj(M(1,1));
 end
FigHandle = figure;
figureh=plot(lamdapump,10*log10(1+Gain0),'b',lamdapump,10*log10(1+Gainsbs),'g',lamdapump,10*log10(Gv),'r','Linewidth',5);
hold on
xlabel('\lambda_P (nm)','Fontsize',18)
ylabel('Signal Gain (dB)','Fontsize',18)
legend('Without SBS',' With SBS ideal ',' With SBS actual')
title('Gain curves with SBS','fontsize',18)
%set(gca,'XTick',1300:10:1800)
set(gca,'fontsize',18)
%ylim([0 12])
hold off

代码不起作用。我认为原因是当使用圆形函数时它会舍入到零。如果我删除圆形功能它不再有效。关于如何让我的代码再次运行的任何想法? 有没有机会解决圆函数,因为我需要采取n步。但是我根本不能这样做,因为L非常小。我需要L的值保持小。 我为长代码和解释道歉。可以自由提问!![The image shows the outcome of the first code which is working just fine.In the second code, the third figure which is the main figure is not plotting and the error as expected is vectors must have same length] 1

0 个答案:

没有答案