声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 810|回复: 1

[编程技巧] 帮忙看看问题在哪?谢谢!!!

[复制链接]
发表于 2009-5-15 17:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
主程序
function mapro

global m
clear,
clf;

%%%%%%%%%%%%%%  参数设置  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k0=3.3*10^7;
g=6.0*10^7;
q=10*10^-3;                                           %tao
p=1.0*10^-14;                                          %ibxt
fs=1.6384*10^6;
ts=0;
tf=0.04;
Ip=0.002;
N=2^16;
h=[k0,g,Ip,p];
%%%%%%%%%%%%%%%% 调用子程序求初态 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[E0,D0]=initiality(h);
X1=[E0(1);D0(1)];
X2=[E0(2);D0(2)];
X3=[E0(3);D0(3)];
%%%%%%%%%%%%%%%%%%% 调用子程序 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t=linspace(ts,tf,N-1);
m=input('type into the modulation index m=');
sol=ode45(@vdp2,t,X1);
%%%%%%%%%%%%%%%%%%%%% 求功率谱 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
El=deval(sol,t,1);
D=deval(sol,t,2);
Il=abs(El).^2;
Fl=fftshift(fft(Il));
mFl=abs(Fl(1:N));
f=(0:N-1)*fs/N;
%%%%%%%%%%%%%% 画图 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(1)
plot(t,El,'r');
xlabel('time/s');
ylabel('the laser field');
title('时序图')
figure(2)
plot(D,El,'c*');                              
xlabel('population inversion');                                 
ylabel('laser field');
title('相图')
                                                   
figure(3)
plot(t,Il)
xlabel('time/s');
ylabel('the output power/w');
title('激光输出')

figure(4)
plot(f,mFl,'k')
xlabel('frequency in Hz');
ylabel('magnitude of Fl');
title('功率谱')

save data t EL Il D Fl f

子程序1
%calculate initiality
function[x,y]=initiality(h)
x=roots([h(1),-h(4),h(1)+h(1)*h(3)-h(2)*h(3)+h(2),-(1+h(3))*h(4)]);
y=h(1)/h(2)-h(4)/h(2)/x;
子程序2
function subpro=vdp2(t,X)
global  m
subpro=zeros(2,1);
El=X(1);D=X(2);
%%%%%%%%%%%%%%%%%  参数设置  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k0=3.3*10^7;                                %损耗系数
g=6.0*10^7;                                 %增益系数
w=3.5*10^5;                                 %调制角频率
q=10*10^-3;                                 %自发辐射项
p=1.0*10^-14;                               %激光上能级寿命
Ip= 0.002;                                    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k=k0*(1+m*sin(w.*t));                  %正弦形式的损耗调制

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

subpro(1)=-k*El+g*El.*D+p;
subpro(2)=-((1+Ip+El.^2).^D-Ip+1)/q;
调试时,老出现
???  In an assignment  A(I) = B, the number of elements in B and
I must be the same.
Error in ==> vdp2 at 21
subpro(1)=-k*El+g*El.*D+p;

Error in ==> mapro at 33
sol=ode45(@vdp2,t,X1);
回复
分享到:

使用道具 举报

发表于 2009-5-15 18:52 | 显示全部楼层
Ref: 13F
常见的程序出错问题整理 (eight)
http://forum.vibunion.com/forum/thread-46001-1-1.html
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-17 08:23 , Processed in 0.056750 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表