Professional Documents
Culture Documents
PGCC MAT-2430-XD01H
MATLAB #01
Summer 2014
Project #1 25 points
The MATLAB prompt is >>
Operators for real numbers are: + - * / and ^ for addition,
subtraction, multiplication, division, and raising to a power.
To inhibit output from a command end the line with a semicolon.
Values can be stored in variables: X=5 stores the value 5 in the
variable X.
To see more than the default 5 digits on numeric values type format
long
To return to 5 digits type format short
To leave MATLAB enter quit or click the X box, top right.
To define a vector such as u=<1,2,3> type u=[1,2,3]. In other
words, use square brackets to indicate a vector.
To find the dot product of two vectors, type dot(u,v)
To find the cross product of two vectors, type cross(u,v)
To define variables a, b, and c as a symbolic variable type syms a
b c
To define a matrix of elements cij where i is the row number and j
is the column number type [c11 c12 c13;c21 c22 c23;c31 c32 c33]
This can be done with symbolic variables i j and k in row 1 if they
are defined as symbolic.
Additional MATLAB files can be found at the following web site:
o http://www.math.umd.edu/~jec/matcomp/matcompmfiles/mfiles.html
To plot a line in a two-dimensional rectangular coordinate system,
type plot([x0 x1],[y0 y1])
To set the viewing window (similar to the TI WINDOW) type
axis([xmin xmax ymin ymax])
To turn the grid on type grid on
To plot a line in a 3-D coordinate system, type plot3([x0 x1] ,[y0
y1] ,[z0 z1])
To plot a line given its parametric equations
x x1 at , y y1 bt , z z1 ct type the following series of commands (pick
two different values for t1 and t2): x = [x1 + a*t1,x1 + a*t2] y
= [y1 + b*t1,y1 + b*t2] z = [z1 + c*t1,z1 + c*t2] plot3(x,y,z)
To set the viewing window for a 3-D plot type axis([xmin xmax ymin
ymax zmin zmax])
r
A plane has an equation of the form ax by cz d 0 where n a, b, c is
a vector normal to the plane. Select a point P0 ( x0 , y0 , z0 ) in the
plane. To graph the plane type p0=[x0 y0 z0] n=[a b c]
plane(p0,n)
321707075.doc
Page | 1
HCC MATH-240-J445
MATLAB #01
PGCC MAT-2430-XD01H
Summer 2014
r
and v 3, 0, 4
command.
u=[1 4 3];%vector u
v=[-3 0 4];%vector v
dot_product=dot(u,v)
Matlab Response:
dot_product =
9
r
2. Find the cross product of u 1, 4,3
r
and v 3, 0, 4
using the
cross command.
u=[1 4 3];%vector u
v=[-3 0 4];%vector v
cross_product= cross(u,v)
Matlab Response:
cross_product=
16
-13
12
Page | 2
HCC MATH-240-J445
MATLAB #01
PGCC MAT-2430-XD01H
Summer 2014
Matlab response:
dot_product =
12*k*conj(k) - 3*i*conj(i)
cross_product =
[ -16*j*k, 13*i*k, -12*i*j]
r r ur
4. Find the triple product u g v w
r
r
where u 3, 4, 2 , v 0,1,1 , and
ur
w 8,1, 0 .
u=[-3 4 2];
v=[0 1 1];
w=[8 1 0];
%to find u.(v*w)
c_product=cross(v,w);
tripleproduct1=dot(u,c_product)
%to find u*(v*w)
tripleproduct2=cross(u,c_product)
matlab response:
tripleproduct1 =
19
tripleproduct2 =
-48
-26
-20
r
5. Graph the line parallel to the vector u 2, 3, 4
that passes
Page | 3
HCC MATH-240-J445
PGCC MAT-2430-XD01H
MATLAB #01
Summer 2014
Your project must show the MATLAB commands that you use to solve the
above problems. But, be sure that you do not just show the MATLAB
commands your printout/document must also include the answers.
Also, be sure that the MATLAB commands you show give you the correct
answer to the problem!
321707075.doc
Page | 4