plotting - advanced. fplot plots a function f(x) written as a string within quotation marks. the...

15
Plotting - Advanced

Upload: giles-horton

Post on 23-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Plotting - Advanced

Page 2: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

FPLOT

Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x.

The lower and upper limits for x are given as a row vector with two values, as the second argument of the function.

Example:fplot('x.*sin(x)', [0 10*pi])

Page 3: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

FPLOT example

Example of fplot: fplot('x.*sin(x)', [0 10*pi])

Page 4: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Logarithmic plotting

Many functions tend to increase exponentially after some point. This presents problems in viewing the behavior (or see the values) of the function where it is close to zero.

To accentuate low values and compress the high ones, the axis where the values get too high are plotted on a logarithmic scale.

In MATLAB, we can plot x-axis, y-axis, or both axes on a logarithmic scale.

Page 5: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Chart type: SEMILOGX

Example:x= e-t, y= t, 0≤t≤2

t= linspace(0, 2*pi, 200);x= exp(-t); y= t;plot(x,y); grid;

t= linspace(0, 2*pi, 200);x= exp(-t); y= t;semilogx(x,y); grid;

Page 6: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Chart type: SEMILOGY

Example:y= e-x2, -3 ≤ x ≤ 3

x= linspace(-3, 3, 101);y= exp(-x.^2);plot(x,y); grid;

x= linspace(-3, 3, 101);y= exp(-x.^2);semilogy(x,y); grid;

Page 7: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Chart type: LOGLOG

Example:x= e-t, y= 100 + e2t, 0 ≤ t ≤ 2

t= linspace(0, 2*pi, 200);x= exp(-t); y= 100+exp(2*t);plot(x,y); grid;

t= linspace(0, 2*pi, 200);x= exp(-t); y= 100+exp(2*t);loglog(x,y); grid;

Page 8: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Chart type: POLAR

Plots a radial function around 360° Example:

r2= 2 sin 5t, 0 ≤ t ≤ 2

t= linspace(0, 2*pi, 200);r= sqrt(abs(2*sin(5*t)));polar(t,r);

Page 9: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Chart type: FILL

Example:r2= 2 sin 5t, 0 ≤ t ≤ 2x= r cos t, y= r sin t

t= linspace(0, 2*pi, 200);r= sqrt(abs(2*sin(5*t)));x= r.*cos(t); y= r.*sin(t);fill(x,y,'r'); axis('square');

Page 10: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Chart type: BAR

Example:r2= 2 sin 5t, 0 ≤ t ≤ 2y= r sin t

t= linspace(0, 2*pi, 200);r= sqrt(abs(2*sin(5*t)));y= r.*sin(t);bar(t,y); axis([0 pi 0 inf]);

Page 11: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Chart type: BARH

Example: World population by continents

cont= char('Asia', 'Europe', 'Africa', 'N.America', 'S.America');pop=[3332; 696; 694; 437; 307];barh(pop);for i=1:5 gtext(cont(i,:));endxlabel('Population in millions');title('World population 1992');

Page 12: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Chart type: PIE

Example: World population by continents

cont= char('Asia', 'Europe', 'Africa', 'N.America', 'S.America');pop=[3332; 696; 694; 437; 307];pie(pop);for i=1:5 gtext(cont(i,:));endtitle('World population 1992');

Page 13: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Chart type: COMET

Animated linear plot. Example: b= a sin a, 0 ≤ a ≤ 10

a= linspace(0, 10*pi, 2000); b= a.*sin(a); pause(2); comet(a, b);

Page 14: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Multiple charts in a window

Multiple plots may be placed in a window using the SUBPLOT command.

Syntax:subplot(rows, columns, active)

Any plotting command acts on the active subplot only.

Active plot is selected in row-major order.

1 2 3

4 5 6

Page 15: Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower

Multiple charts in a window

Example:

x= linspace(0, 4*pi, 100); subplot(3,2,1); plot(x, sin(x));subplot(3,2,2); plot(2*x, sin(2*x));subplot(3,2,3); plot(x, cos(x));subplot(3,2,4); plot(2*x, cos(2*x));subplot(3,2,5); plot(x, tan(x));subplot(3,2,6); plot(2*x, tan(2*x));