Math_1920___Computer_guide -...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Math
1920
–
Computer
guide
 Basic
Instructions
for
Computer
Graphing
 
 Basic
Rules:
 1. The
following
commands
are
useful,
but
Matlab
has
an
extensive
help
feature
if
 you
know
how
to
use
it.

Try
typing
‘help’,
‘help
elfun’,
‘help
graph2d’,
and
help
 ‘graph3d’
for
additional
commands.
 2. Use
of
the
‘;’
at
the
end
of
a
line
silences
the
output.
 3. Use
‘.*’
‘.^’,
and
‘./’
operators.

They
force
term
wise
operations.


 4. Matlab
lets
you
run
scripts,
click
on
File‐>
new
‐>
m‐file.

To
run
your
script,
save
 it
and
type
the
name
of
the
script
in
the
matlab
window.
 5. Matlab
will
ignore
any
commands
following
a
‘%’.
 6. ‘Clear’
will
reset
all
variable
names
in
matlab.
 
 Sample
Programs:
 
 
 Plot
a
space­curve
(Helix)
 
 
 t=0:0.2:20;

 %Set
values
for
the
parameter.





t
=
x0
:
spacing
:
xf
 

 
 x=cos(t);
 
 

 
 y=sin(t);
 

 
 z=t;
 
 

 
 plot3(x,y,z);
 %plot
the
curve
 

 
 xlabel('x‐axis');
ylabel('y‐axis');
zlabel('z‐axis');

 %label
the
axis
 
 
 Plot
a
space­curve
(Spiral­helix)
 
 
 t=0:0.2:20;

 %Set
values
for
the
parameter.
 

 
 x=t.*cos(t);
 
 

 
 y=t.*sin(t);
 

 
 z=sqrt(t);
 
 

 
 plot3(x,y,z,'r‐*');


 %('r‐*')
r
red
line,
‐
continuous,
*
mark
each
point
 

 
 xlabel('x‐axis');
ylabel('y‐axis');
zlabel('z‐axis');

 %label
the
axis
 
 
 Plot
a
plane
 
 
 [x,y]=meshgrid(0:0.2:3,0:0.1:2);



%set
x
and
y
values
by
 
 
 z=3*x+4*y+2;

 
 










%
meshgrid(x_values,y_values)
 
 
 mesh(x,y,z);
 
 
 %plot
the
surface
 
 
 
 Plot
a
surface
 
 
 [x,y]=meshgrid(‐3:0.2:3,‐2:0.1:2);



%set
x
and
y
values
 
 
 z=‐x.^2‐y.^2+4;
 
 
 mesh(x,y,z);
 
 
 Plot
a
surface,
line,
and
point
of
intersection
 
 
 [x,y]=meshgrid(‐5:0.2:5,‐5:0.1:5);
 

 
 z=‐x.^2‐y.^2+4;
 %surface
#1
 

 
 mesh(x,y,z);






%plot
surface
 





 
 hold
 





 
 t=‐4:0.1:2;
 





 
 plot3(2+t,2+t,‐4+8*t,'g','linewidth',2);



%plot
line
 





 
 plot3(2,2,‐4,'ko','markersize',10,'markerfacecolor','k')
%plot
point
 
 
 
 
 
 
 
 
 
 
 
 Additional
Comments:
 
 
 u=[2,3,4];
 
 
 
 v=[4,5,2];
 
 
 
 w=cross(u,v)
 
 
 
 y=dot(u,v)
 
 
 
 
 syms
t
s
 
 
 
 q=[t,t^2,cos(t)];
 
 
 dq=diff(q,t)
 
 
 
 Q=int(q,t)
 
 
 
 Please
see
attached
*.m
file.
 
 
 
 
 
 
 
 
 
 
 
 
 Jan
29th
2009
 Two
surfaces
and
the
curve
of
intersection
 
 figure;
 
 [x,y]=meshgrid(‐5:0.2:5,‐5:0.1:5);
 

 z1=‐x.^2‐y.^2+4;
 %surface
#1
 

 z2=3*x+4*y+2;






%surface
#2
 

 surf(x,y,z1);






%plot
surface
#1
 





 pause(1)















%wait
one
second
 





 shading
interp;




%smooth
the
paraboloid
plot.
 





 pause(1)















%wait
one
second
 





 hold;














%don’t
erase
any
plots.
 

 mesh(x,y,z2);






%plot
surface
#2
 





 pause(1)















%wait
one
second
 





 
 
 %
Plot
the
curve
of
intersection 
 theta=0:0.01:2*pi;

%set
the
parameter
theta
 





 r=‐3/2*cos(theta)‐2*sin(theta)+1/2*sqrt((3*cos(theta)+4*sin(theta)).^2+8);
 





 x=r.*cos(theta);
 





 y=r.*sin(theta);
 





 z=4‐r.^2;
 





 plot3(x,y,z,'k','linewidth',5)

%standard
plot,
but
thicker
line.
 


 %create
vector
u
 %create
vector
v
 %take
the
cross
product
w=(u
x
v)
 %take
the
dot
product
y=(u·v)
 %create
symbols
 %create
vector
valued
function
 %take
the
derivative
of
q
 %integrate
q
(don’t
forget
to
add
C)
 
 ...
View Full Document

Ask a homework question - tutors are online