image thumbnail
from Essential MATLAB by Brian Hahn
Companion software for Essential MATLAB for Scientists and Engineers

fig14_3b.m
% this is the version of Fig 14_3 that can be printed
A = [ -8/3 0 0; 0 -10 10; 0 28 -1 ];
y = [35 -10 -7]';
h = 0.01;
p = plot3(y(1),y(2),y(3),'o', 'markersize', 2,'EraseMode','none');
% Set EraseMode to none
set(gcf,'BackingStore','off');
set(gca,'DrawMode','Fast');
% Set BackingStore to off and DrawMode to Fast to make it quicker
axis([0 50 -25 25 -25 25])
set(p,'color', [0 0 0])
xd = get(p,'Xdata');
yd = get(p,'Ydata');
zd = get(p,'Zdata');
for i=1:2000
     A(1,3) = y(2);
     A(3,1) = -y(2);
     ydot = A*y;
     y = y + h*ydot;
     % Change coordinates
%    set(p,'XData',y(1),'YData',y(2),'ZData',y(3))
     xd(i+1) = y(1);
     yd(i+1) = y(2);
     zd(i+1) = y(3);
     set(p,'XData',xd,'YData',yd,'ZData',zd)
%    set(p,'color', [0 0 0])
%    drawnow
 end

%comet3(xd,yd,zd) % joins points with lines

Contact us at files@mathworks.com