CSC 113, Fall 2010
Lab Assignment 7
All example functions or scripts below should be created in your editor and saved to your workspace,
so that you may run them.
1. Consider the following M
ATLAB
function which accepts a twoelement vector, and plots it
as a vector in the plane:
function
handle = vectorplot(xvec)
%
% Plots a 2element vector in the plane, specified by
% the coordinates contained in xvec, and returns a handle to
% the line so drawn.
handle =
line
([0 xvec(1)],[0 xvec(2)],’linewidth’,2);
end
Save the function as “vectorplot.m” and test it by creating the following script:
% Create a figure on which to draw
figure
(1)
clf
;
% set the axis ranges
axis
([1 1 1 1]);
hold
on
% put a circle at the origin:
plot
(0,0,’o’)
%
% Plot a vector, and place an "x" at its end:
xvec = [0.9 0.3];
vectorplot(xvec);
plot
(xvec(1), xvec(2), ’x’);
% Another one
yvec = [0.6 0.6];
vectorplot(yvec);
plot
(yvec(1), yvec(2), ’x’);
2. Suppose we create a
2
×
2
matrix with the following script:
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '10
 PhillipRegali
 Vector Space, Cos, Ring, xvec, (xvec)

Click to edit the document details