<html lang="en"> <head> <title>Two-dimensional Function Plotting - GNU Octave</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Octave"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Two_002dDimensional-Plots.html#Two_002dDimensional-Plots" title="Two-Dimensional Plots"> <link rel="prev" href="Axis-Configuration.html#Axis-Configuration" title="Axis Configuration"> <link rel="next" href="Two_002ddimensional-Geometric-Shapes.html#Two_002ddimensional-Geometric-Shapes" title="Two-dimensional Geometric Shapes"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Two-dimensional-Function-Plotting"></a> <a name="Two_002ddimensional-Function-Plotting"></a> <p> Next: <a rel="next" accesskey="n" href="Two_002ddimensional-Geometric-Shapes.html#Two_002ddimensional-Geometric-Shapes">Two-dimensional Geometric Shapes</a>, Previous: <a rel="previous" accesskey="p" href="Axis-Configuration.html#Axis-Configuration">Axis Configuration</a>, Up: <a rel="up" accesskey="u" href="Two_002dDimensional-Plots.html#Two_002dDimensional-Plots">Two-Dimensional Plots</a> <hr> </div> <h5 class="subsubsection">15.2.1.2 Two-dimensional Function Plotting</h5> <p>Octave can plot a function from a function handle inline function or string defining the function without the user needing to explicitly create the data to be plotted. The function <code>fplot</code> also generates two-dimensional plots with linear axes using a function name and limits for the range of the x-coordinate instead of the x and y data. For example, <pre class="example"> fplot (@sin, [-10, 10], 201); </pre> <p class="noindent">produces a plot that is equivalent to the one above, but also includes a legend displaying the name of the plotted function. <!-- fplot scripts/plot/fplot.m --> <p><a name="doc_002dfplot"></a> <div class="defun"> — Function File: <b>fplot</b> (<var>fn, limits</var>)<var><a name="index-fplot-1206"></a></var><br> — Function File: <b>fplot</b> (<var>fn, limits, tol</var>)<var><a name="index-fplot-1207"></a></var><br> — Function File: <b>fplot</b> (<var>fn, limits, n</var>)<var><a name="index-fplot-1208"></a></var><br> — Function File: <b>fplot</b> (<var><small class="dots">...</small>, fmt</var>)<var><a name="index-fplot-1209"></a></var><br> <blockquote><p>Plot a function <var>fn</var> within defined limits. <var>fn</var> is a function handle, inline function, or string containing the name of the function to evaluate. The limits of the plot are given by <var>limits</var> of the form <code>[</code><var>xlo</var><code>, </code><var>xhi</var><code>]</code> or <code>[</code><var>xlo</var><code>, </code><var>xhi</var><code>, </code><var>ylo</var><code>, </code><var>yhi</var><code>]</code>. <var>tol</var> is the default tolerance to use for the plot, and if <var>tol</var> is an integer it is assumed that it defines the number points to use in the plot. The <var>fmt</var> argument is passed to the plot command. <pre class="example"> fplot ("cos", [0, 2*pi]) fplot ("[cos(x), sin(x)]", [0, 2*pi]) </pre> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dplot.html#doc_002dplot">plot</a>. </p></blockquote></div> <p>Other functions that can create two-dimensional plots directly from a function include <code>ezplot</code>, <code>ezcontour</code>, <code>ezcontourf</code> and <code>ezpolar</code>. <!-- ezplot scripts/plot/ezplot.m --> <p><a name="doc_002dezplot"></a> <div class="defun"> — Function File: <b>ezplot</b> (<var>f</var>)<var><a name="index-ezplot-1210"></a></var><br> — Function File: <b>ezplot</b> (<var>fx, fy</var>)<var><a name="index-ezplot-1211"></a></var><br> — Function File: <b>ezplot</b> (<var><small class="dots">...</small>, dom</var>)<var><a name="index-ezplot-1212"></a></var><br> — Function File: <b>ezplot</b> (<var><small class="dots">...</small>, n</var>)<var><a name="index-ezplot-1213"></a></var><br> — Function File: <b>ezplot</b> (<var>h, <small class="dots">...</small></var>)<var><a name="index-ezplot-1214"></a></var><br> — Function File: <var>h</var> = <b>ezplot</b> (<var><small class="dots">...</small></var>)<var><a name="index-ezplot-1215"></a></var><br> <blockquote> <p>Plot the curve defined by <var>f</var> in two dimensions. The function <var>f</var> may be a string, inline function or function handle and can have either one or two variables. If <var>f</var> has one variable, then the function is plotted over the domain <code>-2*pi < </code><var>x</var><code> < 2*pi</code> with 500 points. <p>If <var>f</var> has two variables then <var>f</var><code>(</code><var>x</var><code>,</code><var>y</var><code>) = 0</code> is calculated over the meshed domain <code>-2*pi < </code><var>x</var><code> | </code><var>y</var><code> < 2*pi</code> with 60 by 60 in the mesh. For example: <pre class="example"> ezplot (@(<var>x</var>, <var>y</var>) <var>x</var>.^2 - <var>y</var>.^2 - 1) </pre> <p>If two functions are passed as strings, inline functions or function handles, then the parametric function <pre class="example"> <var>x</var> = <var>fx</var> (<var>t</var>) <var>y</var> = <var>fy</var> (<var>t</var>) </pre> <p class="noindent">is plotted over the domain <code>-2*pi < </code><var>t</var><code> < 2*pi</code> with 500 points. <p>If <var>dom</var> is a two element vector, it represents the minimum and maximum value of <var>x</var>, <var>y</var> and <var>t</var>. If it is a four element vector, then the minimum and maximum values of <var>x</var> and <var>t</var> are determined by the first two elements and the minimum and maximum of <var>y</var> by the second pair of elements. <p><var>n</var> is a scalar defining the number of points to use in plotting the function. <p>The optional return value <var>h</var> is a graphics handle to the created plot. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dplot.html#doc_002dplot">plot</a>, <a href="doc_002dezplot3.html#doc_002dezplot3">ezplot3</a>. </p></blockquote></div> <!-- ezcontour scripts/plot/ezcontour.m --> <p><a name="doc_002dezcontour"></a> <div class="defun"> — Function File: <b>ezcontour</b> (<var>f</var>)<var><a name="index-ezcontour-1216"></a></var><br> — Function File: <b>ezcontour</b> (<var><small class="dots">...</small>, dom</var>)<var><a name="index-ezcontour-1217"></a></var><br> — Function File: <b>ezcontour</b> (<var><small class="dots">...</small>, n</var>)<var><a name="index-ezcontour-1218"></a></var><br> — Function File: <b>ezcontour</b> (<var>h, <small class="dots">...</small></var>)<var><a name="index-ezcontour-1219"></a></var><br> — Function File: <var>h</var> = <b>ezcontour</b> (<var><small class="dots">...</small></var>)<var><a name="index-ezcontour-1220"></a></var><br> <blockquote> <p>Plot the contour lines of a function. <var>f</var> is a string, inline function or function handle with two arguments defining the function. By default the plot is over the domain <code>-2*pi < </code><var>x</var><code> < 2*pi</code> and <code>-2*pi < </code><var>y</var><code> < 2*pi</code> with 60 points in each dimension. <p>If <var>dom</var> is a two element vector, it represents the minimum and maximum value of both <var>x</var> and <var>y</var>. If <var>dom</var> is a four element vector, then the minimum and maximum value of <var>x</var> and <var>y</var> are specify separately. <p><var>n</var> is a scalar defining the number of points to use in each dimension. <p>The optional return value <var>h</var> is a graphics handle to the created plot. <pre class="example"> f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2); ezcontour (f, [-3, 3]); </pre> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dezplot.html#doc_002dezplot">ezplot</a>, <a href="doc_002dezcontourf.html#doc_002dezcontourf">ezcontourf</a>, <a href="doc_002dezsurfc.html#doc_002dezsurfc">ezsurfc</a>, <a href="doc_002dezmeshc.html#doc_002dezmeshc">ezmeshc</a>. </p></blockquote></div> <!-- ezcontourf scripts/plot/ezcontourf.m --> <p><a name="doc_002dezcontourf"></a> <div class="defun"> — Function File: <b>ezcontourf</b> (<var>f</var>)<var><a name="index-ezcontourf-1221"></a></var><br> — Function File: <b>ezcontourf</b> (<var><small class="dots">...</small>, dom</var>)<var><a name="index-ezcontourf-1222"></a></var><br> — Function File: <b>ezcontourf</b> (<var><small class="dots">...</small>, n</var>)<var><a name="index-ezcontourf-1223"></a></var><br> — Function File: <b>ezcontourf</b> (<var>h, <small class="dots">...</small></var>)<var><a name="index-ezcontourf-1224"></a></var><br> — Function File: <var>h</var> = <b>ezcontourf</b> (<var><small class="dots">...</small></var>)<var><a name="index-ezcontourf-1225"></a></var><br> <blockquote> <p>Plot the filled contour lines of a function. <var>f</var> is a string, inline function or function handle with two arguments defining the function. By default the plot is over the domain <code>-2*pi < </code><var>x</var><code> < 2*pi</code> and <code>-2*pi < </code><var>y</var><code> < 2*pi</code> with 60 points in each dimension. <p>If <var>dom</var> is a two element vector, it represents the minimum and maximum value of both <var>x</var> and <var>y</var>. If <var>dom</var> is a four element vector, then the minimum and maximum value of <var>x</var> and <var>y</var> are specify separately. <p><var>n</var> is a scalar defining the number of points to use in each dimension. <p>The optional return value <var>h</var> is a graphics handle to the created plot. <pre class="example"> f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2); ezcontourf (f, [-3, 3]); </pre> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dezplot.html#doc_002dezplot">ezplot</a>, <a href="doc_002dezcontour.html#doc_002dezcontour">ezcontour</a>, <a href="doc_002dezsurfc.html#doc_002dezsurfc">ezsurfc</a>, <a href="doc_002dezmeshc.html#doc_002dezmeshc">ezmeshc</a>. </p></blockquote></div> <!-- ezpolar scripts/plot/ezpolar.m --> <p><a name="doc_002dezpolar"></a> <div class="defun"> — Function File: <b>ezpolar</b> (<var>f</var>)<var><a name="index-ezpolar-1226"></a></var><br> — Function File: <b>ezpolar</b> (<var><small class="dots">...</small>, dom</var>)<var><a name="index-ezpolar-1227"></a></var><br> — Function File: <b>ezpolar</b> (<var><small class="dots">...</small>, n</var>)<var><a name="index-ezpolar-1228"></a></var><br> — Function File: <b>ezpolar</b> (<var>h, <small class="dots">...</small></var>)<var><a name="index-ezpolar-1229"></a></var><br> — Function File: <var>h</var> = <b>ezpolar</b> (<var><small class="dots">...</small></var>)<var><a name="index-ezpolar-1230"></a></var><br> <blockquote> <p>Plot a function in polar coordinates. The function <var>f</var> is either a string, inline function or function handle with one arguments defining the function. By default the plot is over the domain <code>0 < </code><var>x</var><code> < 2*pi</code> with 60 points. <p>If <var>dom</var> is a two element vector, it represents the minimum and maximum value of both <var>t</var>. <var>n</var> is a scalar defining the number of points to use. <p>The optional return value <var>h</var> is a graphics handle to the created plot. <pre class="example"> ezpolar (@(t) 1 + sin (t)); </pre> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dpolar.html#doc_002dpolar">polar</a>, <a href="doc_002dezplot.html#doc_002dezplot">ezplot</a>, <a href="doc_002dezsurf.html#doc_002dezsurf">ezsurf</a>, <a href="doc_002dezmesh.html#doc_002dezmesh">ezmesh</a>. </p></blockquote></div> </body></html>