You are on page 1of 10

2/9/2010

V th trong
Matlab

ntnhut@hcmus.edu.vn

TH 2D


Lnh plot
>> plot(x,f(x))

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

ntnhut@hcmus.edu.vn

2/9/2010

V d hm plot


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

ntnhut@hcmus.edu.vn

ntnhut@hcmus.edu.vn

2/9/2010

Tham s ng nt ca th


>> plot(x,y,LinestyleMarkerColor)
Linestyle (nt v)

-
--
:
-.

ntnhut@hcmus.edu.vn

Marker (nh du nt v)
+

h/hexagram

>

s/square

<

d/diamond

p/pentagram

ntnhut@hcmus.edu.vn

2/9/2010

Color (mu sc)


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

ntnhut@hcmus.edu.vn

V d v th vi cc tham s
>> x = 0:pi/20:2*pi;
>> plot(x, sin(x),-.*r);

ntnhut@hcmus.edu.vn

2/9/2010

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');

ntnhut@hcmus.edu.vn

V d v nhiu th vi cc tham s
>>
>>
>>
>>
>>
>>

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

ntnhut@hcmus.edu.vn

10

2/9/2010

ntnhut@hcmus.edu.vn

11

Cc tham s khc


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.

ntnhut@hcmus.edu.vn

12

2/9/2010

V d v th vi cc tham s khc
>> x = -pi:pi/10:pi;
>> y = tan(sin(x)) - sin(tan(x));
>> plot(x,y,--rs','LineWidth',
2,'MarkerEdgecolor',
'k','MarkerFacecolor',
'g', 'MarkerSize',10)

ntnhut@hcmus.edu.vn

13

ntnhut@hcmus.edu.vn

14

2/9/2010

Xc nh kiu trc ta


Lnh axis
axis([xmin xmax ymin ymax])

Ty chnh cc kiu trc ta

axis on/off/auto
axis normal/square/equal/tight
axis ij/xy
grid on/off
ntnhut@hcmus.edu.vn

15

V d v kiu trc to

ntnhut@hcmus.edu.vn

16

2/9/2010

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]);

ntnhut@hcmus.edu.vn

17

ntnhut@hcmus.edu.vn

18

2/9/2010

Xc nh cc mc ghi trn trc ta

XTick v YTick

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'})

ntnhut@hcmus.edu.vn

19

ntnhut@hcmus.edu.vn

20

10

You might also like