-
Notifications
You must be signed in to change notification settings - Fork 3
/
lorenz_equations.m
94 lines (79 loc) · 4.26 KB
/
lorenz_equations.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
94
% ----------------------------------------------------------------------- %
% __ __ _______ _ ____ _ _ _______ _____ %
% | \/ | /\|__ __| | /\ | _ \| || | /\|__ __| __ \ %
% | \ / | / \ | | | | / \ | |_) | || |_ / \ | | | |__) | %
% | |\/| | / /\ \ | | | | / /\ \ | _ <|__ _/ /\ \ | | | ___/ %
% | | | |/ ____ \| | | |____ / ____ \| |_) | | |/ ____ \| | | | %
% |_| |_/_/ \_|_| |______/_/ \_|____/ |_/_/ \_|_| |_| %
% %
% ----------------------------------------------------------------------- %
% %
% Author: Alberto Cuoci <alberto.cuoci@polimi.it> %
% CRECK Modeling Group <http://creckmodeling.chem.polimi.it> %
% Department of Chemistry, Materials and Chemical Engineering %
% Politecnico di Milano %
% P.zza Leonardo da Vinci 32, 20133 Milano %
% %
% ----------------------------------------------------------------------- %
% %
% This file is part of Matlab4ATP framework. %
% %
% License %
% %
% Copyright(C) 2022 Alberto Cuoci %
% Matlab4ATP is free software: you can redistribute it and/or %
% modify it under the terms of the GNU General Public License as %
% published by the Free Software Foundation, either version 3 of the %
% License, or (at your option) any later version. %
% %
% Matlab4CFDofRF is distributed in the hope that it will be useful, %
% but WITHOUT ANY WARRANTY; without even the implied warranty of %
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
% GNU General Public License for more details. %
% %
% You should have received a copy of the GNU General Public License %
% along with Matlab4ATP. If not, see <http://www.gnu.org/licenses/>. %
% %
%-------------------------------------------------------------------------%
% %
% Code: Lorenz's equations %
% %
% ----------------------------------------------------------------------- %
close all;
clear variables;
global sigma beta rho
%% User-defined data
%-------------------------------------------------------------------------%
sigma = 10;
beta = 8/3;
rho = 28;
%% Numerical solution
%-------------------------------------------------------------------------%
% Initial conditions: case 1
psiInitial = [0.1 0.1 0.1]';
[t1,psi1] = ode15s(@LorenzEquations, 0:0.1:100, psiInitial);
% Initial conditions: case 2 (perturbed)
psiInitial = [0.1000001 0.1 0.1]';
[t2,psi2] = ode15s(@LorenzEquations, 0:0.1:100, psiInitial);
%% Plotting the results
%-------------------------------------------------------------------------%
% Plotting x vs time
subplot(3,1,1);
plot(t1, psi1(:,1), 'b');
title ('Case 1'); ylabel('x');
subplot(3,1,2);
plot(t2, psi2(:,1), 'r');
title('Case 2'); ylabel('x');
subplot(3,1,3)
plot(t1, psi1(:,1)-psi2(:,1), 'g');
title('Difference'); ylabel('x_1-x_2');
xlabel('time');
%% Lorenz Equations
%-------------------------------------------------------------------------%
function dpsidt = LorenzEquations(t,psi)
global sigma beta rho
dpsidt = zeros(3,1);
dpsidt(1) = sigma*(psi(2)-psi(1));
dpsidt(2) = rho*psi(1)-psi(2)-psi(1)*psi(3);
dpsidt(3) = -beta*psi(3)+psi(1)*psi(2);
end