%this code solves the differential equations of the Lorenz system and plots solutions in several different ways. 
%values of parameters and the right hand sides of equations are defined in rhs.m


% Pick maximum integration time. (The solution will be found for time from 0 to this value). To see your solution nicely you may want to adjust this. 

time=30;

%Choose initial conditions for x,y,z
x0=[1;2;3];

% Plot a point for the initial condition
% In 3d plot
figure(1)
plot3(x0(1),x0(2),x0(3),'or','markersize',3,'markerfacecolor','r')
hold on

% In 2d plot
figure(2)
plot(x0(1),x0(3),'or','markersize',3,'markerfacecolor','r')
hold on

%Solve equations with right-hand sides given in rhs.m, initial conditions defined above.

[t,x] = ode45('rhs',[0 time],x0);

%PLot solutions
%3d
figure(1)
  plot3(x(:,1),x(:,2),x(:,3),'color','k','marker','.','markersize',.5,'linewidth',1,'linestyle','-')
xlabel('x')
ylabel('y')
zlabel('z')

%In x,z projection
figure(2)
plot(x(:,1),x(:,3),'color','k','marker','.','markersize',.5,'linestyle','-')
xlabel('x')
ylabel('z')

%Time course of x(t), y(t) and z(t)
figure(3)
subplot(3,1,1)
plot(t,x(:,1))
ylabel('x')
subplot(3,1,2)
plot(t,x(:,2))
ylabel('y')
subplot(3,1,3)
plot(t,x(:,3))
ylabel('z')
xlabel('t')
