 |
School of Computer Science
Computer Science COMP 199 (Winter term)
Excursions in Computing Science
%MATLABpak08 minParabola, iterateHitPause
%minParabola.m THM 060808
% plot distance (x,y) from (x0,y0) = (1,.5)
[x,y] = meshgrid(-1.5:.25:3);
d = x.*(x-2) + y.*(y-1) + 5/4;
meshc(x,y,d), xlabel('x'), ylabel('y'), zlabel('dist^2 = (x-1)^2 + (y-1/2)^2')
%iterateHitInput.m THM 060808
% function iterateHitInput(A,b)
% in: matrix A, vector b; out: plot only
% uses quiver3 to show sequence b, Ab, AAB, .. until user types '0'
% type '1' to continue after each plot
function iterateHitInput(A,b)
for j=1:size(b), normalizer(j)=1; end
b=b/(normalizer*b)
quiver3(0,0,0,b(1),b(2),b(3),0)
xlabel('x'), ylabel('y'), zlabel('z')
axis([0 1 -.2 .6 0 1])
hold on
while input('again? (0 or 1)')
b = A*b;
b=b/(normalizer*b)
quiver3(0,0,0,b(1),b(2),b(3),0)
end
hold off