format compact x=[-1 0 1]; A = [x;1 1 1]'; b = [1 0 2]'+[.5 -1 .5]'; p = ((A'*A)\A'*b); y = A*p; perp=[y';b']; v1=[ 0.9235 -0.8870 -0.0000 -0.0182 0.7777 0.2024 1.7976 -1.3888 1.5945 0.4150 -0.8767 14.4336 0 0 0 1.0000 ]; v2 = [ 1.3252 -0.7490 0 -0.2881 0.5611 0.2482 1.8544 -1.3319 1.3888 0.6144 -0.7492 14.3730 0 0 0 1.0000 ]; v3 = [ 1.6868 -0.5373 -0.0000 -0.5747 0.2234 0.1754 1.9563 -1.1775 1.0511 0.8250 -0.4158 14.2699 0 0 0 1.0000 ]; grd=-2:.5:2; grd=grd(grd~=0); g2=[grd(1),grd(end)] s1a=A*[0*grd+grd(1);grd]; % each col has one end point of a line to draw. s1b=A*[0*grd+grd(end);grd]; % the other end points, varying the constant term. s2a=A*[grd;0*grd+grd(1)]; % each col has one end point of a line to draw. s2b=A*[grd;0*grd+grd(end)]; % the other end point, varying the slope. zb=A*[0*g2;g2]; % the coordinate passing through the origin. zm=A*[g2;0*g2]; % the coordinate passing through the origin. figure(1);clf; hold off tt=[g2(1):.05:g2(2)]; plot(x,b,'r*',tt,polyval(p,tt),'k-',[x;x],[y';b'],'r-'); axis equal grid hold on; plot(x,[1,1,1],'b*'); plot(x,[-1,0,1],'mo'); hold off figure(2);clf; hold off plot3([s1a(1,:),s2a(1,:);s1b(1,:),s2b(1,:)], ... [s1a(2,:),s2a(2,:);s1b(2,:),s2b(2,:)], ... [s1a(3,:),s2a(3,:);s1b(3,:),s2b(3,:)], ... '-k',... 0,0,0,'ko',... b(1),b(2),b(3),'r*',... perp(:,1),perp(:,2),perp(:,3),'r-'); axis equal grid view(v2);v=view; hold on; plot3(zb(1,:),zb(2,:),zb(3,:),'b-'); plot3(zm(1,:),zm(2,:),zm(3,:),'m-'); plot3(A(1,2),A(2,2),A(3,2),'b*'); plot3(A(1,1),A(2,1),A(3,1),'m*'); text(A(1,2),A(2,2),A(3,2),'1,1,1'); text(A(1,1),A(2,1),A(3,1),'-1,0,1'); h=text(b(1),b(2),b(3),'b');set(h,'color',[1 0 0]); text(0,0,0,'origin') plot3(y(1),y(2),y(3),'r*') hold off A b p disp('A*p = ') disp(A*p);