function out=lincomb(u,v,w) % % LINCOMB, LINCOMB(U,V), LINCOMB(U,V,W) draws a grid of parallelograms % determined by the row or col vectors u and v (size (2,1) or (1,2). % Overlays the vector w, and expresses it as a linear combination % of the vectors u and v. This program is self-demonstrating. % % Author: Matthias Kawski, Oct.10, 1996 % http://math.la.asu.edu/~kawski % % Changes: July 2000. Color of parallelogram from yellow to black. % Larger grid. % if nargin == 0 u=[3,1]; v=[1,3]; w=[7,5]; end; if size(u)==[2,1]; u=u'; end; if size(v)==[2,1]; v=v'; end; n=30; clf hold on for k=[-n:n] plot([-n*u(1)+k*v(1),n*u(1)+k*v(1)],[-n*u(2)+k*v(2),n*u(2)+k*v(2)],'g-'); plot([-n*v(1)+k*u(1),n*v(1)+k*u(1)],[-n*v(2)+k*u(2),n*v(2)+k*u(2)],'c-'); end; window=[-10,10,-10,10]; axis(window); plot([window(1),window(2)],[0,0],'b'); plot([0,0],[window(3),window(4)],'b'); if (nargin>2) | (nargin==0) if size(w)==[2,1]; w=w'; end; plot([0,w(1)],[0,w(2)],'r'); c=inv([u',v'])*w'; text(-5,8,['w = ',num2str(c(1)),' u + ',num2str(c(2)),' v']); plot([0,c(1)*u(1)],[0,c(1)*u(2)],'k-'); plot([0,c(2)*v(1)],[0,c(2)*v(2)],'k-'); plot([c(2)*v(1),c(1)*u(1)+c(2)*v(1)],[c(2)*v(2),c(1)*u(2)+c(2)*v(2)],'k-'); plot([c(1)*u(1),c(1)*u(1)+c(2)*v(1)],[c(1)*u(2),c(1)*u(2)+c(2)*v(2)],'k-'); end;