I am trying to simulate trajectories in the Lorenz System in MATLAB, with currently using the following code -
clear all
clf;
clc;
% Solution
[t1,x1] = ode45('g',[0 30],[0;2;0]);
[t2,x2] = ode45('g2',[0 30],[0;2.001;0]);
[C,h] = size(x2);
ang = 0;
for j = 1:C
p1(j,:)= x1(j,:);
p2(j,:)= x2(j,:); % Plot
plot3(p1(:,1),p1(:,2),p1(:,3),'k', p2(:,1),p2(:,2),p2(:,3),'r'); hold on;
plot3(p1(j,1),p1(j,2),p1(j,3),'ko','markerfacecolor','k');
plot3(p2(j,1),p2(j,2),p2(j,3),'rd','markerfacecolor','r'); hold off
axis([-20 20 -40 40 0 50])
axis off
set(gca,'color','none') % Rotation
camorbit(ang,0,[p1(1,1),p1(1,2),p1(1,3)])
ang = ang + (360/C); % Record
set(gcf, 'units','normalized','outerposition',[0 0 1 1])
F(j)= getframe(gcf);
end
movie(F)
clf;
close;
With the functions g, g2 defined in the same way:
function xdot = g(t,x)
xdot = zeros(3,1);
sig = 10;
rho = 28;
bet = 8/3;
xdot(1) = sig*(x(2)-x(1));
xdot(2) = rho*x(1)-x(2)-x(1)*x(3);
xdot(3) = x(1)*x(2)-bet*x(3);
Which is the Lorenz System. The purpose of this whole code is to make a movie of the trajectory of two initial states that vary very slightly, in order to demonstrate the chaotic behaviour of this system. The code itself does in fact work, but takes all of my computer's memory, and in an attempt to make a .avi file of the trajectory, it complained about exceeding 7.5 GB - which is of course way too much for this simulation.
My question consists of two parts:
(1) How do I manage this code in order to make it run more smoothly?
(2) How can I make a .avi file of the trajectory? I tried to find a way on the internet for a long time, but either MATLAB or my computer gave up every time.
Thanks in advance!