Professional Documents
Culture Documents
MATLAB’de Grafik
Bilgisayar Programlama
MATLAB
MATLAB’de Grafikler
ÖRNEK
y x 2 9 x 20
Fonksiyonun herhangi bir aralıktaki grafiği aşağıda verilen MATLAB
komutlarını icrası ile elde edilebilir
x=1:20;
y=x.^2-9*x-20;
plot(x,y)
What
GRAFİKis a computer???
DÜZENLEYEN KOMUTLAR MATLAB’de Grafik
Bir grafikte aşağıda verilen tanımlamalar mevcut olmalıdır:
Grafiğin başlığı
Eksen takımlarının isimleri
ÖRNEK x=[1:1:20];
y=x.^2-9*x-20;
plot(x,y)
title('x.^2-9*x-20 fonksiyonun grafigi');
xlabel('x ekseni');
ylabel('y ekseni');
ÇOKLU
What isGRAFİKLER
a computer??? MATLAB’de Grafik
MATLAB’de tek bir grafik penceresinde birden fazla grafik çizdirmek
mümkündür.
ÖRNEK
y(t ) 3t 2 5t 8
y(t ) 6t 5
t=[0:1:20];
y_1=t.^3-5*t+8;
y_2=6*t-5;
plot(t,y_1,t,y_2)
UYGULAMA
What is a computer??? MATLAB’de Grafik
0 ila 2*pi arasındaki açı değerleri için sin(x) ve cos(x) fonksiyonlarını aynı
grafik penceresinde çizen bir MATLAB programı yazınız
GRAFİKLERDE ÇEŞİTLİ
What is a computer???
DÜZENLEMELER
MATLAB’de Grafik
ÖRNEK
x=[0:pi/10:4*pi];
y1=sin(x);
y2=cos(x);
plot(x,y1,'b.:',x,y2,'b<-')
xlabel('x degisimi');
ylabel('Fonksiyonun degisimi');
title('sinx ve türevinin değişimi')
legend('sin(x)','cos(x)',-1)
Figure fonksiyonu ile çoklu
What is a computer???
grafikler
MATLAB’de Grafik
ÖRNEK
x=0:pi/30:2*pi;
y1=sin(x);
y2=cos(x);
figure(1),plot(x,y1,'bo:')
figure(2),plot(x,y2,'r*-')
Subplot
What isfonksiyonu ile Alt Grafikler
a computer??? MATLAB’de Grafik
Aynı grafik penceresinde birden fazla grafik çizmek için subplot (a,b,c)
fonksiyonu icra edilir. Burada
a: grafik penceresinin satır sayısı
b: grafik penceresinin sütün sayısı
c: alt pencere numarası
Örnek
What is a computer??? MATLAB’de Grafik
subplot(2,2,1) f(x)=sin(x) f(x)=cos(x)
1 1
x=0:pi/30:2*pi;
0.5 0.5
y1=sin(x);
0 0
plot(x,y1)
-0.5 -0.5
title('f(x)=sin(x)')
-1 -1
subplot(2,2,2) 0 2 4 6 8 0 2 4 6 8
y2=cos(x); 2
x 10
16
f(x)=tan(x)
5
x 10
15
f(x)=cot(x)
plot(x,y2)
1 0
title('f(x)=cos(x)')
subplot(2,2,3) 0 -5
y3=tan(x); -1 -10
0 2 4 6 8 0 2 4 6 8
plot(x,y3)
title('f(x)=tan(x)')
subplot(2,2,4)
y4=cot(x);
plot(x,y4)
title('f(x)=cot(x)')
Hold
Whatkomutu
is a computer??? MATLAB’de Grafik
Aynı eksen takımında birden fazla grafik çizmek için hold komutu kullanılır.
Figure fonksiyonu kullanılmadığı sürece işletilen herbir plot komutu aynı
grafik penceresinde işlem görür.
ÖRNEK
x=0:pi/30:2*pi;
y1=sin(x);
plot(x,y1,'k*:')
hold
y2=exp(2*sin(x));
plot(x,y2,'ro--')
legend('sin(x)','\bf{e}^{2*sin(x)}')
Data
WhatGrafikleri
is a computer??? MATLAB’de Grafik
Pasta Grafikleri: 2D 11%
22%
11%
22% 28%
6%
33%
Pasta Grafikleri: 3D
x = [1 3 0.5 2.5 2]
explode = [0 1 0 0 0]
pie3(x,explode)
colormap hsv
22%
11%
28%
33%
6%
Üç Boyutlu
What Grafikler
is a computer??? MATLAB’de Grafik
Çubuk Grafikleri: 3D
Y = [10 5 6 18 4 5];
X= [25 35 30 45 50 55]
Z=[X;Y]
bar3(Z,0.5)
60
40
20
6
0
5
1 4
3
2 2
1
What
Üç is a Grafikler
Boyutlu computer??? MATLAB’de Grafik
Eş yükselti eğrileri
[X,Y] = meshgrid(-2:.2:2,-2:.2:3);
Z = X.*exp(-X.^2-Y.^2);
[C,h] = contour(X,Y,Z);
clabel(C,h) 3
0
colormap cool 2.5
1.5
1 -0 .1 0.1
-0 .2 0.2
0
0.5 -0 .3 0.3
0.1
-0 .1
0.4
-0.1
0 -0
0.1
.4
-0 .2
0.2
0.2
2
-0.5
-0 .
-0 .3 0.3
-1
-0.1 0.1
0
-1.5
-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
What
Üç is a Grafikler
Boyutlu computer??? MATLAB’de Grafik
[X,Y] = meshgrid([-2:.25:2]);
Z = X.*exp(-X.^2-Y.^2);
contour3(X,Y,Z,30)
surface(X,Y,Z,'EdgeColor',[.8 .8 .8],'FaceColor','none')
grid off
view(-15,25)
colormap cool 0.4
0.2
-0.2
-0.4
2
1.5 2
0 0.5 1
-2 -1.5 -1 -0.5
-2
What
Üç is a Grafikler
Boyutlu computer??? MATLAB’de Grafik
[X,Y] = meshgrid([-2:.25:2]);
Z = (X.^2-Y.^2);
meshc(X,Y,Z)
colormap cool
-2
-4
2
1 2
0 1
0
-1 -1
-2 -2
Uygulamalar
What is a computer??? MATLAB’de Grafik
x y
Uygulama 1: Yanda verilen dataları bir dosyadan okuyup 1 10
grafiğini çizen bir MATLAB programı yazınız
3 13
Uygulama 2: Aşağıda verilen fonksiyonu x:-4:4, y=-4:4 5 15
aralığında 3D olarak çiziniz. 8 16
z x3 y 3 cos( x * y) 9 18
z x2 y 2