⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 代码汇总.m

📁 一个小小的c语言编程
💻 M
📖 第 1 页 / 共 5 页
字号:
        movie(mmm,rotate_repeat,rotate_zhen);         %movie(mmm,a,b)以每秒b帧速度(可调节速度),重复播放a次。 开始会回放一遍
     case 'roll x',
        donghua_x,
     case 'roll_y',
        donghua_y,
   end 
   
   
function DX=DYDt2(t,X,flag,sigma,b,r)
switch flag
    case ''
        DX=[-sigma*X(1)+sigma*X(2);r*X(1)-X(2)-X(1).*X(3);X(1).*X(2)-b*X(3)];
    case 'init'
        options.RelTol=1e-5;options.AbsTol=1e-5;
    otherwise 
        error(['Unknown flag ''' flag '''.']);
        
end        


function florenz_xy(h_menu1_sub1_text_sigma,h_menu1_sub1_str_sigma,sigma,h_menu1_sub1_text_b,h_menu1_sub1_str_b,b,h_menu1_sub1_text_r,h_menu1_sub1_str_r,r,X0,Y0,Z0,t0,tf)
global X1 X2 X3 t                                                        %解方程并画出x-y的黑色平面轨线图                
global h_menu1_sub1_str_sigma h_menu1_sub1_str_b h_menu1_sub1_str_r
global h_menu1_sub1_text_sigma h_menu1_sub1_text_b h_menu1_sub1_text_r
global h_menu1_sub1_text_bifucationz1 h_menu1_sub1_text_bifucationz2

cla,set(h_menu1_sub1_text_sigma,'string',[h_menu1_sub1_str_sigma,sprintf('%1.4g\',sigma)]);
cla,set(h_menu1_sub1_text_b,'string',[h_menu1_sub1_str_b,sprintf('%1.4g\',b)]);
cla,set(h_menu1_sub1_text_r,'string',[h_menu1_sub1_str_r,sprintf('%1.4g\',r)]);
cla,set(h_menu1_sub1_text_bifucationz1,'string',['z1=',sprintf('%1.4g\',r-1)]);
cla,set(h_menu1_sub1_text_bifucationz2,'string',['z2=',sprintf('%1.4g\',r-1+(sigma+1)^2/(4*sigma))]);

tspan=[t0,tf];f0=[X0;Y0;Z0];
[t,X]=ode45('DYDt2',tspan,f0,[],sigma,b,r);
X1=X(:,1);X2=X(:,2);X3=X(:,3);
x1=-20;x2=20;y1=-30;y2=30;
grid on ,            %设置网格线    
hold on             %保持网格线
axis auto,          %自动容纳图形用axis auto,plot使用
plot(X1,X2,'k-'),hold on,


function florenz_xyz(htext_speed,str_speed,time,htext_sigma,str_sigma,sigma,htext_b,str_b,b,htext_r,str_r,r,X0,Y0,Z0,t0,tf)
global X1 X2 X3 t %解微分方程的函数
cla,set(htext_sigma,'string',[str_sigma,sprintf('%1.4g\',sigma)]);
cla,set(htext_b,'string',[str_b,sprintf('%1.4g\',b)]);
cla,set(htext_r,'string',[str_r,sprintf('%1.10f\',r)]);
cla,set(htext_speed,'string',[str_speed,sprintf('%1.4g\',time)]);

tspan=[t0,tf];
f0=[X0;Y0;Z0];
[t,X]=ode45('DYDt2',tspan,f0,[],sigma,b,r);
X1=X(:,1);X2=X(:,2);X3=X(:,3);
x1=-20;x2=20;y1=-30;y2=30;z1=0;z2=60;

singularity1_x=0;singularity1_y=0;singularity1_z=0;
singularity2_x=(b*(r-1))^(1/2);singularity2_y=(b*(r-1))^(1/2);singularity2_z=r-1;
singularity3_x=-(b*(r-1))^(1/2);singularity3_y=-(b*(r-1))^(1/2);singularity3_z=r-1;

figure(1)
plot3(X1,X2,X3,'W'),hold on

if r<=1
    plot3(singularity1_x,singularity1_y,singularity1_z,'k.','MarkerSize',20)       %画奇点
    text(singularity1_x,singularity1_y,singularity1_z,' O')
      else 
   plot3(singularity1_x,singularity1_y,singularity1_z,'k.','MarkerSize',20)       %画奇点
   text(singularity1_x,singularity1_y,singularity1_z,' O')
   plot3(singularity2_x,singularity2_y,singularity2_z,'k.','MarkerSize',20)       %画奇点
   text(singularity2_x,singularity2_y,singularity2_z,' C+')
   plot3(singularity3_x,singularity3_y,singularity3_z,'k.','MarkerSize',20)       %画奇点
   text(singularity3_x,singularity3_y,singularity3_z,' C-')
end
temp_time=time/400;
mycomet3(X1,X2,X3,0.02,temp_time);hold on,
title('Lorenz phase'),xlabel('x'),ylabel('y'),zlabel('z'),
%legend('z',4)    %选4可使彗星图不被刷掉                 
hold off


function florenz_xz(h_menu1_sub3_text_sigma,h_menu1_sub3_str_sigma,sigma,h_menu1_sub3_text_b,h_menu1_sub3_str_b,b,h_menu1_sub3_text_r,h_menu1_sub3_str_r,r,X0,Y0,Z0,t0,tf)
global X1 X2 X3 t                                                        %解方程并画出x-z的黑色平面轨线图                
global h_menu1_sub3_str_sigma h_menu1_sub3_str_b h_menu1_sub3_str_r
global h_menu1_sub3_text_sigma h_menu1_sub3_text_b h_menu1_sub3_text_r

cla,set(h_menu1_sub3_text_sigma,'string',[h_menu1_sub3_str_sigma,sprintf('%1.4g\',sigma)]);
cla,set(h_menu1_sub3_text_b,'string',[h_menu1_sub3_str_b,sprintf('%1.4g\',b)]);
cla,set(h_menu1_sub3_text_r,'string',[h_menu1_sub3_str_r,sprintf('%1.4g\',r)]);

tspan=[t0,tf];f0=[X0;Y0;Z0];
[t,X]=ode45('DYDt2',tspan,f0,[],sigma,b,r);
X1=X(:,1);X2=X(:,2);X3=X(:,3);
x1=-20;x2=20;y1=-30;y2=30;
grid on ,            %设置网格线    
hold on             %保持网格线
axis auto,          %自动容纳图形用axis auto,plot使用
plot(X1,X3,'k-'),hold on,


function florenz_yz(h_menu1_sub2_text_sigma,h_menu1_sub2_str_sigma,sigma,h_menu1_sub2_text_b,h_menu1_sub2_str_b,b,h_menu1_sub2_text_r,h_menu1_sub2_str_r,r,X0,Y0,Z0,t0,tf)
global X1 X2 X3 t                                                        %解方程并画出y-z的黑色平面轨线图                
global h_menu1_sub2_str_sigma h_menu1_sub2_str_b h_menu1_sub2_str_r
global h_menu1_sub2_text_sigma h_menu1_sub2_text_b h_menu1_sub2_text_r
global h_menu1_sub2_text_bifucationx1 h_menu1_sub2_text_bifucationx2

cla,set(h_menu1_sub2_text_sigma,'string',[h_menu1_sub2_str_sigma,sprintf('%1.4g\',sigma)]);
cla,set(h_menu1_sub2_text_b,'string',[h_menu1_sub2_str_b,sprintf('%1.4g\',b)]);
cla,set(h_menu1_sub2_text_r,'string',[h_menu1_sub2_str_r,sprintf('%1.4g\',r)]);
cla,set(h_menu1_sub2_text_bifucationx1,'string',['x1=',sprintf('%1.4g\',(b-1)/2)]);
cla,set(h_menu1_sub2_text_bifucationx2,'string',['x2=',sprintf('%1.4g\',-(b-1)/2)]);

tspan=[t0,tf];f0=[X0;Y0;Z0];
[t,X]=ode45('DYDt2',tspan,f0,[],sigma,b,r);
X1=X(:,1);X2=X(:,2);X3=X(:,3);
x1=-20;x2=20;y1=-30;y2=30;
grid on ,            %设置网格线    
hold on             %保持网格线
axis auto,          %自动容纳图形用axis auto,plot使用
plot(X2,X3,'k-'),hold on,


function gonglvpu_x(x)
figure(20),
clf reset
str='X功率谱分析 ';
set(gcf,'name',str,'numbertitle','off');

if mod(length(x),2)~=0
    x(length(x)+1)=0;
end
f1=fft(x);
f2=conj(f1);
normal=f1.*f2;
axis_x=([1:length(x)]*0.014).\1;
grid on,hold on,
plot(log(normal),'k'),


function gonglvpu_y(x)
figure(21),
clf reset
str='Y功率谱分析 ';
set(gcf,'name',str,'numbertitle','off');

if mod(length(x),2)~=0
    x(length(x)+1)=0;
end
f1=fft(x);
f2=conj(f1);
normal=f1.*f2;
axis_x=([1:length(x)]*0.014).\1;
grid on,hold on,
plot(log(normal),'k'),


function gonglvpu_z(x)
figure(22),
clf reset
str='Z功率谱分析 ';
set(gcf,'name',str,'numbertitle','off');

if mod(length(x),2)~=0
    x(length(x)+1)=0;
end
f1=fft(x);
f2=conj(f1);
normal=f1.*f2;
axis_x=([1:length(x)]*0.014).\1;
grid on,hold on,
plot(log(normal),'k'),


function Lyapunov(x)
if length(x)<400
   helpdlg('数据量需要大于400,请重新选定时间','提示信息');pause(3),
end   
dm=26;tao=5;set_error=0.001;
for i=0:(dm-1)
    for j=1:(length(x)/1.2)
       k=j+i*tao;
           Y(i+1,j)=x(k);
    end
end 

l=1; i=1; p=1;                      %  i为Y的一列,j为Y的一列 
while i<length(Y)
     for j=p:length(Y)               %求两点之间距离
        if j>i
        e_normal=max(abs(Y(:,i)-Y(:,j)));
        end
     end    
    flag=e_normal-set_error;
            if flag>0
              d(l)=e_normal;l=l+1;
              %i=i+1;
                 for j=1:length(Y)             %找离点最小距离的点  
                    l_normal(j)=max(abs(Y(:,i)-Y(:,j)));
                 end
              p=find((l_normal-min(l_normal))==0);            %找到最近点Y(:,j)
           else 
              j=j+1;i=i+1;                    %范数小于set_error,Y(:,i)和Y(:,j)继续向前一步  
           end
end
 
LE1=0;
for i=1:l
    f1=d(i);f2=d(1);
 LE1=log10(f1/f2)+LE1;
end
LE1=1/(l*0.014)*LE1,


function my_comet_strange_xy(x,y,p,time)  %函数体参量表一定没有常数或代数式.x,y平面对应不同奇点的轨线彗星图
global X3 t
figure(9)
set(gcf,'unit','normalized','position',[0.31,0.53,0.64,0.35]);
set(gcf,'defaultuicontrolunits','normalized');
set(gcf,'defaultuicontrolfontsize',12);
set(gcf,'defaultuicontrolfontname','隶书');
str='平面对应不同奇点的轨线彗星图';
set(gcf,'name',str,'numbertitle','off');	
h_axes=axes('position',[0.05,0.2,0.6,0.7]);	 
set(h_axes,'xlim',[-40,40],'ylim',[-40,40]);

if nargin == 0, error('Not enough input arguments.'); end
if nargin < 2, y = x; x = 1:length(y); end
if nargin < 3, p = 0.10; end
ax = newplot;
if ~ishold,
  axis([min(x(isfinite(x))) max(x(isfinite(x))) ...
        min(y(isfinite(y))) max(y(isfinite(y)))])
end
co = get(ax,'colororder');
if size(co,1)>=3,
  % Choose first three colors for head, body, and tail
  head = line('color',co(1,:),'marker','^','erase','xor', ...
              'xdata',x(1),'ydata',y(1));
  body = line('color',co(2,:),'linestyle','-','erase','none', ...
              'xdata',[],'ydata',[]);
  tail = line('color',co(3,:),'linestyle','-','erase','none', ...
              'xdata',[],'ydata',[]);
else
  % Choose first three colors for head, body, and tail
  head = line('color',co(1,:),'marker','o','erase','xor', ...
              'xdata',x(1),'ydata',y(1));
  body = line('color',co(1,:),'linestyle','--','erase','none', ...
              'xdata',[],'ydata',[]);
  tail = line('color',co(1,:),'linestyle','-','erase','none', ...
              'xdata',[],'ydata',[]);
end
m = length(x);
k = round(p*m);

% Grow the body
for i = 2:k+1
   j = i-1:i;
   set(head,'xdata',x(i),'ydata',y(i))
   set(body,'xdata',x(j),'ydata',y(j))
   pause(time)
   drawnow
                                               %开始时速度
end

% Primary loop
for i = k+2:m
   j = i-1:i;
   set(head,'xdata',x(i),'ydata',y(i))
   set(body,'xdata',x(j),'ydata',y(j))
   set(tail,'xdata',x(j-k),'ydata',y(j-k))
   drawnow
   pause(time)                   %连点速度
end

% Clean up the tail             %刷新颜色
for i = m+1:m+k
   j = i-1:i;
   set(tail,'xdata',x(j-k),'ydata',y(j-k))
    drawnow
end
 

function my_comet_strangespace_xyz_x(x,y,z,p,time)  %函数体参量表一定没有常数或代数式.y,z平面的轨线彗星图及x(t)坐标同步运行
global  X1 t
global h_my_menu3_sub2_text_xyz_t h_my_menu3_sub2_text_xyz_z h_my_menu3_sub2_text_xyz_x h_my_menu3_sub2_text_xyz_y%此处一定要写
figure(13)
set(h_my_menu3_sub2_text_xyz_t,'string',['t= ',sprintf('%2.4f\n',0)]);
  set(h_my_menu3_sub2_text_xyz_x,'string',['x= ',sprintf('%2.4f\n',0)]);
  set(h_my_menu3_sub2_text_xyz_y,'string',['y= ',sprintf('%2.4f\n',0)]);
  set(h_my_menu3_sub2_text_xyz_z,'string',['z= ',sprintf('%2.4f\n',0)]);
  
if nargin == 0, error('Not enough input arguments.'); end
if nargin < 3, z = x; x = 1:length(z); y = 1:length(z); end
if nargin < 4, p = 0.10; end

ax = newplot;
if ~ishold,
  axis([min(x(isfinite(x))) max(x(isfinite(x))) min(y(isfinite(y)))  ...
        max(y(isfinite(y))) min(z(isfinite(z))) max(z(isfinite(z)))])
end

co = get(ax,'colororder');

if size(co,1)>=3,
  % Choose first three colors for head, body, and tail
  head = line('color',co(1,:),'marker','o','erase','xor', ...
              'xdata',x(1),'ydata',y(1),'zdata',z(1));
  body = line('color',co(2,:),'linestyle','-','erase','none', ...
              'xdata',[],'ydata',[],'zdata',[]);
  tail = line('color',co(3,:),'linestyle','-','erase','none', ...
              'xdata',[],'ydata',[],'zdata',[]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -