Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Plotting - Advanced

2 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])

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

4 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.

5 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;

6 Chart type: SEMILOGY Example: y= e -x 2, -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;

7 Chart type: LOGLOG Example: x= e -t, y= 100 + e 2t, 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;

8 Chart type: POLAR Plots a radial function around 360° Example: r 2 = 2 sin 5t, 0 ≤ t ≤ 2  t= linspace(0, 2*pi, 200); r= sqrt(abs(2*sin(5*t))); polar(t,r);

9 Chart type: FILL Example: r 2 = 2 sin 5t, 0 ≤ t ≤ 2  x= 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');

10 Chart type: BAR Example: r 2 = 2 sin 5t, 0 ≤ t ≤ 2  y= 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]);

11 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,:)); end xlabel('Population in millions'); title('World population 1992');

12 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,:)); end title('World population 1992');

13 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);

14 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. 123 456

15 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));


Download ppt "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."

Similar presentations


Ads by Google