You are on page 1of 19

V th trong

Matlab

TRONG KHNG GIAN 2 CHIU


Lnh plot

plot(x,f(x))
Vi:
f(x) - hm s cn v
x vect min gi tr ca hm f

V d
V th ca hm y = sin(x)
x = 0:pi/100:2*pi;
y = sin(x);
plot(x, y)

Cc tham s plot(x,y,linestye_marker_color)
linestye

-
--
:
-.

marker
+

h/hexagram

>

s/square

<

d/diamond

p/pentagram

color
r (red)
k(black)
w(white)
y(yellow)
c(cyan)
b(blue)
g(green)
m(magenta)

Lnh hold on
Khi mun v thm th trn th hin c,ta s dng
lnh hold on. tt ch ny,s dng hold off.
V d
x = 0:pi/10:2*pi;
plot(x, sin(x),'->r')
hold on
t =0:1:7;
plot(t, 2*t,'-*b');

V d
x = 0:pi/20:2*pi;
plot(x, sin(x),-.*r);
hold on
plot(x, sin(x pi/2),--om);
plot(x, sin(x pi), :bs);
hold off

Ty chnh mu sc v ln nt v
LineWidth : rng ca nt v, tnh bng pt.
MarkerEdgecolor: mu ca ng vin marker.
MarkerFacecolor: mu bn trong marker.
Markersize: ln ca marker, tnh bng pt.

V d
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'rs','LineWidth',
2,'MarkerEdgecolor',
'k','MarkerFacecolor',
'g', 'Markersize',10)

Xc nh kiu trc ta
Lnh axis
axis([xmin xmax ymin ymax])
Ty chnh cc kiu trc ta

axis
axis
axis
grid

on/off/auto
normal/square/equal/tight
ij/xy
on/off

V d

Xc nh gii hn ta
xlim([xmin xmax])
ylim(ymin ymax])
Xc nh gii hn ca trc Ox v Oy.
V d
x = linspace(0,3,500);
y = 1./(x - 1).^2 + 3./(x - 2).^2;
plot(x,y); grid on;
ylim([0 50]);

Xc nh cc mc ghi trn trc ta


xtick v yticks

V d
x = -pi:.1:pi;
y = sin(x);
plot(x,y)
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',
{'-pi','-pi/2','0','pi/2','pi'})

You might also like