155GIT1 / 9. cvičení

Z GeoWikiCZ

Grafy funkcí

Náplň cvičení

  1. grafické okno figure
  2. grafy funkcí plot(), subplot(), axis()

Ukázky

Grafické okno

figure
figure    # -> 2
figure(4) # -> 4

Grafy funkcí

x = [0:3:360];
y = sin(x*pi/180);
plot(x, y);
%
% nové okno
figure(2)
plot(x, y, 'r+')
%
% více grafů najednou
z = cos(x*pi/180);
plot(x, y, '--b', x, z, ':k');
plot(x, y, '--b', x, z, ':k')
  • popisky
figure(3)
hold on
plot(x,y,'m');
plot(x,z,'b');
title('Funkce sinus a cosinus')
xlim([0 360]);
ylim([-1.2 1.2]);
xlabel('argument ve stupnich')
ylabel('funkcni hodnota')
legend('sinus','cosinus', 'Location', 'Best')
box on
grid on
plot([0 360],[0 0],'k')
hold off
Graf s popisky
  • subplot()
x = 1:100;
figure
% první
subplot(2, 2, 1)
plot(x, x)
% druhý
subplot(2, 2, 2)
plot(x, sqrt(x))
% třetí
subplot(2, 2, 3)
plot(x, log(x))
% čtvrtý
subplot(2, 2, 4)
plot(x, x.^2)
subplot()
  • axis() - omezení oblasti grafu
x = 0:0.1:5;
y = exp(x);
% celý graf
subplot(2, 1, 1)
plot(x, y)
% výsek x <1, 2>; y <0, 10>
subplot(2, 1, 2)
plot(x, y)
axis([1,2,0,10])
axis()

Úlohy