-
Notifications
You must be signed in to change notification settings - Fork 1
/
lorenzModel.m
93 lines (66 loc) · 2.17 KB
/
lorenzModel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
classdef lorenzModel < model
properties
% define parameters and bounds
parameter_names = {'rho','sigma','beta'};
lb = [0 0 0 ];
ub = [100 100 100];
default_values = [28 10 8/3];
variable_names = {'x','y','z'};
live_update = true;
end % end properties
methods
function [m] = evaluate(m)
ic = [.1 .1 .1];
Tspan = [0 max(m.time)];
options = odeset('InitialStep',1e-3,'MaxStep',1e-1,'RelTol',1e-3);
[T, Y] = ode23t(@(t,y) m.lorenzModel_ode(t,y,m.parameters),Tspan,ic,options); % Solve ODE
% re-interpolate and define new time.
m.time = T;
m.prediction.x = Y(:,1);
m.prediction.y = Y(:,2);
m.prediction.z = Y(:,3);
end % end evaluate
function m = plotButterfly(m,action)
if ~isfield(m.handles,'plot_fig')
m.handles.plot_data = [];
% this is being called for the first time
% create a figure
m.handles.plot_fig = figure('position',[50 250 900 740],'NumberTitle','off','IntegerHandle','off','Name','The Lorenz Butterfly','CloseRequestFcn',@m.quitManipulateCallback);
% we need to make only one axes --
m.handles.plot_ax = autoPlot(1,1,true);
xlabel(m.handles.plot_ax,'x')
ylabel(m.handles.plot_ax,'y')
zlabel(m.handles.plot_ax,'z')
hold(m.handles.plot_ax,'on')
% make just one plot
m.handles.plot_data.handles = plot3(NaN,NaN,NaN,'Color','k');
prettyFig();
end
if nargin == 2
if strcmp(action,'update')
m.evaluate;
m.handles.plot_data.handles.XData = m.prediction.x;
m.handles.plot_data.handles.YData = m.prediction.y;
m.handles.plot_data.handles.ZData = m.prediction.z;
m.handles.plot_ax.XLim = [min(m.prediction.x) max(m.prediction.x)];
m.handles.plot_ax.YLim = [min(m.prediction.y) max(m.prediction.y)];
m.handles.plot_ax.ZLim = [min(m.prediction.z) max(m.prediction.z)];
end
end
end
end % end class methods
methods (Static)
function dY = lorenzModel_ode(t,Y,p)
x = Y(1);
y = Y(2);
z = Y(3);
dx = p.sigma*(y-x);
dy = x*(p.rho - z) - y;
dz = x*y - p.beta*z;
dY = Y;
dY(1) = dx;
dY(2) = dy;
dY(3) = dz;
end
end
end % end classdef