1 advanced plotting ผศ. ดร. อนันต์ ผลเพิ่ม anan phonphoem anan...

Post on 27-Dec-2015

254 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

Advanced Plotting

ผศ.ดร.อนั�นัต์ ผลเพิ่��มAnan Phonphoem

http://www.cpe.ku.ac.th/~anananan@cpe.ku.ac.th

2

Outline

xy plot Grid and Axis fplot polynomial plot subplot

3

Plotting

Two-dimensional plot (xy plot) help graph2d

Three-dimensional plot (xyz plot, surface plot) help graph3d

4

xy Plotting Functions

y = f(x) x-axis (abscissa) y-axis (ordinate)

abscissa

ordinate

5

1 2 3 4 5 6 7 8 9 101000

1200

1400

1600

1800

2000

2200

2400

2600

2800

3000

Distance (Km)

Cos

t (B

aht)

Cost of travelling

data1

The Anatomy of a PlotPlot Title

Y-Axis Label

X-Axis Label

Tick Mark

Tick-Mark Label

Legend Data Symbol

6

Plot Essential Features

Axis label with unit Regular spaced tick mark (0.5, 1.0, 1.5,

…) More than one curve use Legend Use Title Plot measured data using Data Symbol Careful about connecting line

7

Plotting example

y = 0.4 √1.8x for 0 ≤x ≤ 52 y = height of a rocket after launch (miles) x = horizontal (downrange) distance (miles)

>>x = [0:0.1:52];>>y = 0.4*sqrt(1.8*x);>>plot(x,y)>>xlabel(’Distance (miles)’)>>ylabel(’Height (miles)’)>>title(’Rocket Height as a Function of Downrange Distance’)

8

Plotting example

9

Grid and axis Commands

grid display gridlines toggle by grid on or grid off

axis override MATLAB axis syntax axis([xmin xmax ymin ymax])

10

Plotting example II

>>x = [0:0.1:52];>>y = 0.4*sqrt(1.8*x);>>plot(x,y)>>xlabel(’Distance (miles)’)>>ylabel(’Height (miles)’)>>title(’Rocket Height as a Function of Downrange Distance’)

>>grid on>>axis([0 52 0 5])

11

Plotting example II

12

Plots of Complex Numbers

plot(y) plot(real(y),imag(y))

>>z = 0.1 + 0.9i;>>n = [0:0.01:10];>>plot(z.^n)>>xlabel(‘Real’), ylabel(‘Imaginary’)

13

Plots of Complex Numbers

14

fplot command

Automatically analyzes the function Then decides the plotting points Syntax fplot(‘string’,[xmin xmax])

string describe function [xmin xmax] value of variable

15

fplot example

>>a_func = ‘cos(tax(x))-tan(sin(x))’;>>fplot(a_func,[1 2])>>xlabel(‘x’),ylabel(‘function’)>>title(‘using fplot’)

16

fplot example I

17

Compare to fplot

>>x=[1:0.01:2];>>y=cos(tax(x))-tan(sin(x));>>plot(x,y)>>xlabel(‘x’),ylabel(‘function’)>>title(‘using fplot’)

18

Compare to fplot

19

Compare to fplot

fplot plot

20

Polynomial Plot

>>x=[-6:0.01:6];>>p=[3,2,-100,2,-7,90];>>plot(x,polyval(p,x))>>xlabel(‘x’),ylabel(‘p’)>>title(‘polynomial plot’)

p(x) = 3x5 + 2x4 – 100x3 +2x2 – 7x+90

21

Polynomial Plot

22

Subplots

Several smaller plots in one figure Syntax subplot(m,n,p)

m m rows n n columns p output plot

23

Subplots example I

>>x = [0:0.01:5];>>y = exp(-1.2*x).*sin(10*x+5);>>subplot(1,2,1)>>plot(x,y),axis([0 5 -1 1])>>x = [-6:0.01:6];>>y = abs(x.^3-100);>>subplot(1,2,2)>>plot(x,y),axis([-6 6 0 350])

y = e-1.2x sin(10x + 5) for 0 ≤x ≤ 5y = |x3 - 100| for -6 ≤ x ≤ 6.

24

Subplots example I

25

Subplots example II

>>x = [0:0.01:5];>>y = exp(-1.2*x).*sin(10*x+5);>>subplot(2,1,1)>>plot(x,y),axis([0 5 -1 1])>>title(‘figure(a)’)>>x = [-6:0.01:6];>>y = abs(x.^3-100);>>subplot(2,2,2)>>plot(x,y),axis([-6 6 0 350])>>title(‘figure(b)’)

26

Subplots example II

top related