Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Plot vectors 2D! With Matlab!

  1. Jul 25, 2010 #1
    Hi... I have four vectors that I need together in one plot and also they should start at (2,2)

    Vector A is a=[5 0]
    B is b=[0 2]
    I obtained unit vector and I need something similar to http://www.scribd.com/doc/13353344/Fundamentals-of-Electromagnetics [Broken] at page nine


    I know the following commands

    pi=[2,2];
    plot( [pi(1),pi(1)+v(1)] , [pi(2),pi(2)+v(2)])

    It works but not with four vectors. What should I do?


    I'm not pretending you to do my homework so that I'm asking for the plot
     
    Last edited by a moderator: May 4, 2017
  2. jcsd
  3. Jul 26, 2010 #2

    marcusl

    User Avatar
    Science Advisor
    Gold Member

    First a comment on Matlab style: It's generally a poor idea to reassign built-in Matlab function or variable names such as you did in the first line. In Matlab, pi is preassigned the value 3.14159...

    On to your question: use the command quiver to plot vectors. The arguments are passed in the form of matrices specifying the x and y starting points and the u and v vector components. For your two vectors a and b:

    x = meshgrid([2,2]);
    y = meshgrid([2,2]);
    u = meshgrid([5,0]);
    v = meshgrid([0,2]);
    quiver(x,y,u,v)

    Add columns to plot more vectors, e.g., u = meshgrid([5,0,14,22,...])
    Matlab renders the arrow a little shorter than you expect, for visual clarity, but you can rescale if desired. REad the help page for quiver.
     
    Last edited by a moderator: May 4, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook