function lorenzgui
%LORENZGUI Plot the orbit around the Lorenz chaotic attractor.
% This function animates the integration of the three coupled
% nonlinear differential equations that define the Lorenz Attractor,
% a chaotic system first described by Edward Lorenz of MIT.
% As the integration proceeds you will see a point moving in
% an orbit in 3-D space known as a strange attractor.
% The orbit ranges around two different critical points, or attractors.
% The orbit is bounded, but may not be periodic and or convergent.
%
% The mouse and arrow keys change the 3-D viewpoint. Uicontrols
% provide "pause", "resume", "stop", "restart", "clear", and "close".
%
% A listbox provides a choice among five values of the parameter rho.
% The first value, 28, is the most common and produces the chaotic
% behavior. The other four values values produce periodic behaviors
% of different complexities. A change in rho becomes effective only
% after a "stop" and "restart".
%
% Reference: Colin Sparrow, "The Lorenz Equations: Bifurcations,
% Chaos, and Strange Attractors", Springer-Verlag, 1982. if ~isequal(get(gcf,'name'),'Lorenz Gui') % This is first entry, just initialize the figure window. rhos = [28 99.65 100.5 160 350];
shg
clf reset
p = get(gcf,'pos');
set(gcf,'color','black','doublebuff','on','name','Lorenz Gui', ...
'menu','none','numbertitle','off', ...
'pos',[p(1) p(2)-(p(3)-p(4))/2 p(3) p(3)]) % Callback to erase comet by jiggling figure position klear = ['set(gcf,''pos'',get(gcf,''pos'')+[0 0 0 1]), drawnow,' ...
'set(gcf,''pos'',get(gcf,''pos'')-[0 0 0 1]), drawnow']; % Uicontrols paws = uicontrol('style','toggle','string','start', ...
'units','norm','pos',[.02 .02 .10 .04],'value',0, ...
'callback','lorenzgui');
stop = uicontrol('style','toggle','string','close', ...
'units','norm','pos',[.14 .02 .10 .04],'value',0, ...
'callback','cameratoolbar(''close''), close(gcf)');
clear = uicontrol('style','push','string','clear', ...
'units','norm','pos',[.26 .02 .10 .04], ...
'callback',klear);
rhostr = sprintf('%6.2f|',rhos);
rhopick = uicontrol('style','listbox','tag','rhopick', ...
'units','norm','pos',[.82 .02 .14 .14], ...
'string',rhostr(1:end-1),'userdata',rhos,'value',1); else % The differential equation is ydot = A(y)*y
% With this value of eta, A is singular.
% The eta's in A will be replaced by y(2) during the integration. rhopick = findobj('tag','rhopick');
rhos = get(rhopick,'userdata');
rho = rhos(get(rhopick,'value'));
sigma = 10;
beta = 8/3;
eta = sqrt(beta*(rho-1));
A = [ -beta 0 eta
0 -sigma sigma
-eta rho -1 ]; % The critical points are the null vectors of A.
% The initial value of y(t) is near one of the critical points. yc = [rho-1; eta; eta];
y0 = yc + [0; 0; 3]; % Integrate forever, or until the stop button is toggled. tspan = [0 Inf];
opts = odeset('reltol',1.e-6,'outputfcn',@lorenzplot,'refine',4);
ode45(@lorenzeqn, tspan, y0, opts, A); end % ------------------------------ function ydot = lorenzeqn(t,y,A)
%LORENZEQN Equation of the Lorenz chaotic attractor.
% ydot = lorenzeqn(t,y,A).
% The differential equation is written in almost linear form.
% ydot = A*y
% where
% A = [ -beta 0 y(2)
% 0 -sigma sigma
% -y(2) rho -1 ]; A(1,3) = y(2);
A(3,1) = -y(2);
ydot = A*y; % ------------------------------ function fin = lorenzplot(t,y,job,A)
%LORENZPLOT Plot the orbit of the Lorenz chaotic attractor. persistent Y if isequal(job,'init') % Initialize axis and comet, R = axis settings, L = length of comet. rho = A(3,2);
switch rho
case 28, R = [ 5 45 -20 20 -25 25]; L = 100;
case 99.65, R = [ 50 150 -35 35 -60 60]; L = 240;
case 100.5, R = [ 50 150 -35 35 -60 60]; L = 120;
case 160, R = [100 220 -40 40 -75 75]; L = 165;
case 350, R = [285 435 -55 55 -105 105]; L = 80;
otherwise, R = [100 250 -50 50 -100 100]; L = 150;
end
set(gcf,'pos',get(gcf,'pos')+[0 0 0 1])
drawnow
set(gcf,'pos',get(gcf,'pos')-[0 0 0 1])
drawnow
if get(gca,'userdata') ~= rho, delete(gca), end
set(gca,'color','black','pos',[.03 .05 .93 .95],'userdata',rho)
axis(R);
axis off comet(1) = line(y(1),y(2),y(3),'linestyle','none','marker','.', ...
'erasemode','xor','markersize',25);
comet(2) = line(NaN,NaN,NaN,'color','y','erasemode','none');
comet(3) = line(NaN,NaN,NaN,'color','y','erasemode','none');
Y = y(:,ones(L,1)); uics = flipud(get(gcf,'children'));
paws = uics(1);
stop = uics(2);
set(paws,'string','pause','callback','','value',0);
set(stop,'string','stop','callback','','value',0); beta = -A(1,1);
eta = sqrt(beta*(rho-1));
yc = [rho-1; eta; eta];
line(yc(1),yc(2),yc(3),'linestyle','none','marker','o','color','g')
line(yc(1),-yc(2),-yc(3),'linestyle','none','marker','o','color','g') ax = [R(2) R(1) R(1) R(1) R(1)];
ay = [R(3) R(3) R(4) R(3) R(3)];
az = [R(5) R(5) R(5) R(5) R(6)];
p = .9;
q = 1-p;
grey = [.4 .4 .4];
line(ax,ay,az,'color',grey);
text(p*R(1)+q*R(2),R(3),p*R(5),sprintf('%3.0f',R(1)),'color',grey)
text(q*R(1)+p*R(2),R(3),p*R(5),sprintf('%3.0f',R(2)),'color',grey)
text(R(1),p*R(3)+q*R(4),p*R(5),sprintf('%3.0f',R(3)),'color',grey)
text(R(1),q*R(3)+p*R(4),p*R(5),sprintf('%3.0f',R(4)),'color',grey)
text(R(1),R(3),p*R(5)+q*R(6),sprintf('%3.0f',R(5)),'color',grey)
text(R(1),R(3),q*R(5)+p*R(6),sprintf('%3.0f',R(6)),'color',grey)
fin = 0; cameratoolbar('setmode','orbit')
uicontrol('style','text','units','norm','pos',[.38 .02 .34 .04], ...
'foreground','white','background','black','fontangle','italic', ...
'string','Click on axis to rotate view') elseif isequal(job,'done') fin = 1; else % Update comet L = size(y,2);
Y(:,end+1:end+L) = y;
comet = flipud(get(gca,'children'));
set(comet(1),'xdata',Y(1,end),'ydata',Y(2,end),'zdata',Y(3,end));
set(comet(2),'xdata',Y(1,2:end),'ydata',Y(2,2:end),'zdata',Y(3,2:end))
set(comet(3),'xdata',Y(1,1:2),'ydata',Y(2,1:2),'zdata',Y(3,1:2))
Y(:,1:L) = [];
drawnow; % Pause and restart uics = flipud(get(gcf,'children'));
paws = uics(1);
stop = uics(2);
rhopick = uics(4);
rho = A(3,2);
while get(paws,'value')==1 & get(stop,'value')==0
set(paws,'string','resume');
drawnow;
end
set(paws,'string','pause')
fin = get(stop,'value') | get(rhopick,'value')==rho;
if fin
set(paws,'value',0,'string','restart','callback','lorenzgui')
set(stop,'value',0,'string','close', ...
'callback','cameratoolbar(''close''), close(gcf)')
end
end

Matlab function lorenzgui的更多相关文章

  1. Calling Matlab function from python: “initializer must be a rectangular nested sequence”

    I am writing a python script from which I hope to call the Matlab anovan function. I have attempted ...

  2. [转] Loren on the Art of MATLAB

    http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/ Loren ...

  3. Interpolation in MATLAB

    Mathematics     One-Dimensional Interpolation There are two kinds of one-dimensional interpolation i ...

  4. Matlab 进阶学习记录

    最近在看 Faster RCNN的Matlab code,发现很多matlab技巧,在此记录: 1. conf_proposal  =  proposal_config('image_means', ...

  5. 【原创】Matlab.NET混合编程技巧之找出Matlab内置函数

                  本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新    Matlab和C#混合编程文章目录 :[目录]Matlab和C#混合编程文章目录 Matlab与.N ...

  6. 以神经网络使用为例的Matlab和Android混合编程

    由于需要在一个Android项目中使用神经网络,而经过测试发现几个Github上开源项目的训练效果就是不如Matlab的工具箱好,所以就想在Android上使用Matlab神经网络代码(可是...) ...

  7. MATLAB仿真总结

    MATLAB仿真过程中,编写MATLAB代码的时候犯了很多错误,做了很多蠢事.记录下自己犯错的点点滴滴,并引以为戒.使用MATLAB版本为2014a,以下内容如有不当还请指正. 1. 仿真开始前清理工 ...

  8. Libsvm:脚本(subset.py、grid.py、checkdata.py) | MATLAB/OCTAVE interface | Python interface

    1.脚本 This directory includes some useful codes: 1. subset selection tools. (子集抽取工具) subset.py 2. par ...

  9. Matlab与C/C++联合编程之Matlab以MEX方式调用C/C++代码(三)

    最近写了个Matlab程序,好慢呐……所以开始学习Matlab与C/C++混合编程.下面写了个测试代码,显示一个Double类型矩阵中的元素. 源代码 #include "mex.h&quo ...

随机推荐

  1. Docker构建文件

    构建文件 创建Dockerfile touch Dockerfile 编辑Dockerfile vim Dockerfile #基于java8版本构建 FROM java:8 #挂载日志目录 VOLU ...

  2. 3 week work—Grid Layout

    HTML: <div class="wrapper"> //建立一个三列轨道网格. <div class="one">One</d ...

  3. 关于Runtime.getRuntime().exec()产生阻塞的2个陷阱

    本文来自网易云社区 背景 相信做java服务端开发的童鞋,经常会遇到Java应用调用外部命令启动一些新进程来执行一些操作的场景,这时候就会使用到Runtime.getRuntime().exec(), ...

  4. 【接口时序】2、Verilog实现流水灯及与C语言的对比

    一. 软件平台与硬件平台 软件平台: 1.操作系统:Windows-8.1 2.开发套件:ISE14.7 3.仿真工具:ModelSim-10.4-SE 硬件平台: 1.FPGA型号:XC6SLX45 ...

  5. Django 通过 mongoengine 连接 MongoDB 进而使用orm进行CRUD

    一. 在python脚本中, 我们通常可以使用pymongo模块实现与mongodb数据库的交互, 但是在使用Django框架进行定制开发的web server 项目中, 仍然使用pymongo模块的 ...

  6. Android开发工程师文集-layout_weight讲解

    前言 大家好,给大家带来Android开发工程师文集-layout_weight讲解的概述,希望你们喜欢 Layout_weight的相关代码展示 <TextView android:layou ...

  7. 阿里开源项目arthas在docker环境初始化

    需求 我前一篇是在window环境下做的测试,实际情况现在的生成环境程序都部署在了docker环境下,此环境对arthas可能会缺失很多必要组件 目前的基础环境是在docker容器中,只存在基本的to ...

  8. Nginx---(main block)

    正常运行必备配置 1,user USERNAME [GROUPAME] ; 指定用于运行worker进程的用户和组:   user nginx nginx; 2, pid /PATH/TO/PID_F ...

  9. docker:(2)通过Dockerfile构建镜像并发布web项目

    上一篇讲解了docker的基本使用 http://www.cnblogs.com/xiaochangwei/p/8204511.html 虽然通过修改获取到的镜像可以达到使用目的,但是多操作几次就会发 ...

  10. python中不同文件中函数和类的调用

    最近在学习Python的时候,遇到了一个不同文件中类无法调用的问题,搜了很多,发现很多人针对 这个问题都说的相当含糊,让我费了好大劲才把这个东东搞明白.记录一下,权且温习. 调用分两种,一种是同种文件 ...