%% Solution to Lorenz Exercise

% Constants
sigma = 10;  % Prandlt number
rho = 28;    % Rayleigh number
beta = 8.0/3;

% Integrate!
lorenz = @(t, n) [sigma*(n(2)-n(1)); n(1)*(rho-n(3))-n(2); n(1)*n(2) - beta*n(3)];
[t, n] = ode45(lorenz, [0 200], [1; 1; 1]);

% Or:
%lorenz = @(t, n, sigma, rho, beta) [sigma*(n(2)-n(1)); n(1)*(rho-n(3))-n(2); n(1)*n(2) - beta*n(3)];
%[t, n] = ode45(@(t, n) lorenz(t, n, 10, 28, 8/3), [0 200], [1; 1; 1]);

x = n(:, 1);
y = n(:, 2);
z = n(:, 3);

plot3(x, y, z)
xlabel('x')
ylabel('y')
zlabel('z')
