Originally Posted by

**fearless901** hi guys my professor gave us this code to work with but i dont understand why i keep getting errors? plz explain why im wrong

__heres the assignment__

plot arrow with tail point P(x0,y0) in xy plane and tip at the point (x0+a,y0+b). Writing Pvector=<x0,y0> and Vvector=<a,b>.

__heres my code__

function y = arrow(P,V,color)

if nargin < 3

color = 'b';

end

x0 = P(1);

y0 = P(2);

a = V(1); b = V(2);

l = max(norm(V), eps);

u = [x0 x0+a]; v = [y0 y0+b];

hchek = ishold;

plot(u,v,color,'LineWidth',2)

hold on

h = l - min(.2*l, .2) ; v = min(.2*l/sqrt(3), .2/sqrt(3) );

a1 = (a*h -b*v)/l;

b1 = (b*h +a*v)/l;

plot([x0+a1, x0+a], [y0+b1, y0+b], color,'LineWidth',2)

a2 = (a*h +b*v)/l;

b2 = (b*h -a*v)/l;

plot([x0+a2, x0+a], [y0+b2, y0+b], color,'LineWidth',2)

if hchek == 0

hold off

end

__heres my errors__

Error in ==> arrow at 7

x0 = P(1);