Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

Functions for Graphing Vector Quantities

Four MATLAB

functions display data consisting of direction vectors and velocity vectors; three create 2-D
plots and one creates 3-D plots
Function Description
compass
Displays vectors e!anating fro! the origin of a polar plot
feather
Displays vectors e"tending fro! e#ually spaced points along a hori$ontal line
quiver
Displays 2-D vectors specified %y &u,v' co!ponents
quiver3
Displays 3-D vectors specified %y &u,v,w' co!ponents
For feather and co!pass plots( you define the vectors using one or t)o argu!ents The argu!ents specify the u
and v co!ponents of the vectors relative to the origin *f you specify t)o argu!ents( the first specifies the u
co!ponents of the vectors( and the second specifies the v co!ponents of the vectors *f you specify one
argu!ent( the functions treat the ele!ents as co!ple" nu!%ers The real parts are the u co!ponents( and the
i!aginary parts are the v co!ponents
For #uiver plots( in addition to the u-v co!ponents( you also specify x,y locations &or x,y,z locations in the case
of quiver3' to esta%lish an origin for each vector
Compass Plots
The compass function sho)s vectors e!anating fro! the origin of a graph The function ta+es ,artesian
coordinates and plots the! on a circular grid
Example Compass Plot of Wind Direction and Speed
This e"a!ple sho)s a co!pass plot indicating the )ind direction and strength during a -2-hour period T)o
vectors define the )ind direction and strength.
wdir = [45 90 90 45 360 335 360 270 335 270 335 335];
kots = [6 6 ! 6 3 9 6 ! 9 "0 "4 "2];
,onvert the )ind direction( given as angles( into radians %efore converting the )ind direction into ,artesian
coordinates.
rdir = wdir # pi$"!0;
[%&'] = po(2cart)rdir&kots*;
compass)%&'*
,reate te"t to annotate the graph.
desc = +,-id .irectio ad /tre0th at,&
,1o0a 2irport for ,&
,3ov4 3 at "!00 throu0h,&
,3ov4 4 at 0600,5;
te%t)62!&"5&desc*
Feather Plots
The feather function sho)s vectors e!anating fro! a straight line parallel to the x-a"is For e"a!ple( create a
vector of angles fro! /01 to 01 and a vector the sa!e si$e( )ith each ele!ent e#ual to "
theta = 9076"070;
r = oes)si8e)theta**;
Before creating a feather plot( transfor! the data into ,artesian coordinates and increase the !agnitude of r to
!a+e the arro)s !ore distinctive.
[u&v] = po(2cart)theta#pi$"!0&r#"0*;
feather)u&v*
a%is equa(
Plotting Complex Numers
*f the input argu!ent 9 is a !atri" of co!ple" nu!%ers( feather interprets the real parts of 9 as the x
co!ponents of the vectors and the i!aginary parts as the y co!ponents of the vectors.
t = 070457"0; : ;ime (imits
s = 0405<i; : /pira( rate
9 = e%p)6s#t*; : =ompute deca'i0 e%poetia(
feather)9*
Printing the Graph
This particular graph loo+s %etter if you change the figure2s aspect ratio %y stretching the figure length)ise
using the !ouse 3o)ever( to !aintain this shape in the printed output( set the figure2s >aper>ositio?ode to
auto
set)0cf&,>aper>ositio?ode,&,auto,*
*n this !ode( MATLAB prints the figure as it appears on screen
!"o#Dimensional Qui$er Plots
The quiver function sho)s vectors at given points in t)o-di!ensional space The x and y co!ponents define
the vectors
A #uiver plot is useful )hen displayed )ith another plot For e"a!ple( create -0 contours of the peaks
function &4ee ,ontour 5lots for !ore infor!ation'
= 62407427240;
[@&A&9] = peaks)*;
cotour)@&A&9&"0*
6o) use 0radiet to create the vector co!ponents to use as inputs to quiver.
[B&C] = 0radiet)9&42*;
4et ho(d to o and add the contour plot.
ho(d o
quiver)@&A&B&C*
ho(d off
!hree#Dimensional Qui$er Plots
Three-di!ensional #uiver plots &quiver3' display vectors consisting of &u(v(w' co!ponents at &x(y($' locations
For e"a!ple( you can sho) the path of a pro7ectile as a function of ti!e(
Assign values to the constants v8 and a.
v8 = "0; : Ce(ocit'
a = 632; : 2cce(eratio
,alculate the height 8 as ti!e varies fro! 0 to " in incre!ents of 04".
t = 074"7";
8 = v8#t < "$2#a#t4D2;
,alculate the position in the x and y directions.
v% = 2;
% = v%#t;
v' = 3;
' = v'#t;
,o!pute the co!ponents of the velocity vectors and display the vectors using the 3-D #uiver plot.
u = 0radiet)%*;
v = 0radiet)'*;
w = 0radiet)8*;
sca(e = 0;
quiver3)%&'&8&u&v&w&sca(e*
view)[70 "!]*

You might also like