Results 1 to 3 of 3

Math Help - mfile code doesnt work, why?

  1. #1
    Newbie
    Joined
    Mar 2009
    Posts
    17

    mfile code doesnt work, why?

    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);
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by fearless901 View Post
    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);
    What does your calling statement look like and what are the values of the arguments passed.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    Code:
    arrow([0 0],[1 1])
    Works for me.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Finding a projection/mapping that doesnt fit on a line
    Posted in the Advanced Algebra Forum
    Replies: 1
    Last Post: December 11th 2010, 04:53 AM
  2. Limits that L'Hopital's Rule doesnt work
    Posted in the Calculus Forum
    Replies: 1
    Last Post: March 2nd 2010, 02:47 PM
  3. Replies: 1
    Last Post: December 10th 2009, 10:48 PM
  4. Replies: 9
    Last Post: May 31st 2009, 09:51 AM
  5. Replies: 4
    Last Post: April 8th 2008, 08:48 PM

Search Tags


/mathhelpforum @mathhelpforum