Bài giảng Vẽ đồ thị trong Matlab

Vẽ đồ thị trong  
Matlab  
TRONG KHÔNG GIAN 2 CHIỀU  
◼ Lệnh plot  
plot(x,f(x))  
Với:  
f(x)- hàm số cần vẽ  
x– vectơ miền giá trị của hàm f  
Ví dụ  
◼ Vẽ đồ thị của hàm y = sin(x)  
x = 0:pi/100:2*pi;  
y = sin(x);  
plot(x, y)  
◼ Các tham số plot(x,y,’linestye_marker_color’)  
linestye  
‘-’  
‘--‘  
‘:’  
‘-.’  
marker  
‘+’  
‘h’/‘hexagram’  
+
‘o’  
^
v
‘*’  
*
‘.’  
>
.
‘s’/‘square’  
<  
‘d’/‘diamond’  
‘p’/‘pentagram’  
color  
‘r’ (red)  
‘k’(black)  
‘w’(white)  
‘y’(yellow)  
‘c’(cyan)  
‘b’(blue)  
‘g’(green)  
‘m’(magenta)  
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  
Tùy chỉnh màu sắc và độ lớn nét vẽ  
◼ LineWidth: độ rộng của nét vẽ, tính bằng pt.  
◼ MarkerEdgecolor: màu của đường viền marker.  
◼ MarkerFacecolor: màu bên trong marker.  
◼ Markersize: độ lớn của marker, tính bằng 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)  
Lệnh hold on  
Khi muốn vẽ thêm đồ thị trên đồ thị hiện có,ta sử dụng  
lệnh hold on. Để tắt chế độ này,sử dụng 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');  
Xác định tọa độ  
◼ Lệnh axis  
axis([xmin xmax ymin ymax])  
◼ Tùy chỉnh các kiểu trục tọa độ  
• axis on/off/auto  
• axis normal/square/equal/tight  
• axis ij/xy  
• grid on/off  
Ví dụ  
Xác định tọa độ  
• xlim([xmin xmax])  
• ylim([ymin ymax])  
Xác định giới hạn của trục 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]);  
Xác định tọa độ  
• xticks 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'})  
y = [0 31 6 5 9];area(y)  
str = 'Jan|Feb|Mar|April|May|June';  
set(gca,'xtick',1:6,...  
'xticklabel',str,'xgrid','on','layer','top')  
set(gca,’XTickLabel’,…  
{’1’;’10’;’100’}  
set(gca,’XTickLabel’,…  
’1|10|100’)  
set(gca,’XTickLabel’,…  
[1;10;100])  
set(gca,’XTickLabel’,0:2)  
set(gca,’XTickLabel’,…  
[’1 ’;’10 ’;’100’])  
Tải về để xem bản đầy đủ
ppt 49 trang myanh 27460 Free
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Vẽ đồ thị trong Matlab", để tải tài liệu gốc về máy hãy click vào nút Download ở trên

File đính kèm:

  • pptbai_giang_ve_do_thi_trong_matlab.ppt