|
楼主 |
发表于 2011-3-26 15:41
|
显示全部楼层
% 计算duffing吸引子的Lyapunov指数谱,随参数B变化
clear all;
clc;
Z1=[ ];
Z2=[ ];
Z3=[ ];
global k;
global B;
k=0.1;
% 初始化输入
yinit = [1,1,1];
orthmatrix = [1 0 0;
0 1 0;
0 0 1];
y = zeros(12,1);
IC(1:3) = yinit;
IC(4:12) = orthmatrix;
InitialTime = 0; % 时间初始值
TimeStep = 1e-2; % 时间步长
wholetimes = 1e5; % 总的循环时间
UpdateStepNum = 10; % 每次演化的步数
iteratetimes = wholetimes/UpdateStepNum; % 演化的次数
DiscardItr=200; %抛弃的不稳定迭代次数
Iteration=UpdateStepNum*TimeStep;
DiscardTime=DiscardItr*Iteration+InitialTime;
mod = zeros(1,3);
d=3; %维数
Sum=zeros(1,d);
n=0; %总的迭代计数
k=0; %对结果有作用的迭代计数
xData=[];
yData=[];
T1=InitialTime;
T2=T1+Iteration;
TSpan=[T1:TimeStep:T2];
options=odeset('RelTol',1e-5,'AbsTol',1e-6);
for B=linspace(0,40,100);
lp=0;
for i=1:iteratetimes
n=n+1;
[t,X] =ode45('duffingfun', TSpan, IC,options);
[rX,cX]=size(X);
L=cX-d*d;
% 取积分得到的最后一个时刻的值
for i=1:d
m1=L+1+(i-1)*d;
m2=m1+d-1;
A(:,i)=(X(rX,m1:m2))';
end
y0 = ThreeGS(A); %正交化
% 取三个向量的模
mod(1) = sqrt(y0(:,1)'*y0(:,1));
mod(2) = sqrt(y0(:,2)'*y0(:,2));
mod(3) = sqrt(y0(:,3)'*y0(:,3));
y0(:,1) = y0(:,1)/mod(1);
y0(:,2) = y0(:,2)/mod(2);
y0(:,3) = y0(:,3)/mod(3);
y(4:12) = y0';
if T2>DiscardTime
Q0=y0;
else
Q0=eye(d);
end
if (T2>DiscardTime )
k=k+1;
T=k*Iteration;
TT=n*Iteration+InitialTime;
%计算lyapunov指数
Sum=Sum+log(abs(mod));
lambda=Sum/T;
%按降序排列指数
Lambda=fliplr(sort(lambda));
xData=[xData;TT];
yData=[yData;lambda];
end
% 重新定义起始时刻
ic=X(rX,1:L);
T1=T1+Iteration;
T2=T2+Iteration;
TSpan=[T1:TimeStep:T2];
IC=[ic(:);y0(:)];
end
end
B=linspace(0,40,100);
plot(B,yData(:,1),'-',B,yData(:,2),'-',B,yData(:,3),'-');
title('Lyapunov exponents spectrum of duffing)
xlabel('B'),ylabel('lyapunov exponents')
grid on
我这段程序在我的电脑上已经busy了四个小时还没有结果,请问哪里出现了问题?? |
|