<html lang="en"> <head> <title>Two-dimensional Function Plotting - Untitled</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="Untitled"> <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 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> Up: <a rel="up" accesskey="u" href="Two_002dDimensional-Plots.html#Two_002dDimensional-Plots">Two-Dimensional Plots</a> <hr> </div> <h5 class="subsubsection">15.1.1.1 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. <!-- ./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-953"></a></var><br> — Function File: <b>fplot</b> (<var>fn, limits, tol</var>)<var><a name="index-fplot-954"></a></var><br> — Function File: <b>fplot</b> (<var>fn, limits, n</var>)<var><a name="index-fplot-955"></a></var><br> — Function File: <b>fplot</b> (<var><small class="dots">...</small>, fmt</var>)<var><a name="index-fplot-956"></a></var><br> <blockquote><p>Plot a function <var>fn</var>, within the defined limits. <var>fn</var> an be either a string, a function handle or an inline function. 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>. <!-- ./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-957"></a></var><br> — Function File: <b>ezplot</b> (<var>fx, fy</var>)<var><a name="index-ezplot-958"></a></var><br> — Function File: <b>ezplot</b> (<var><small class="dots">...</small>, dom</var>)<var><a name="index-ezplot-959"></a></var><br> — Function File: <b>ezplot</b> (<var><small class="dots">...</small>, n</var>)<var><a name="index-ezplot-960"></a></var><br> — Function File: <b>ezplot</b> (<var>h, <small class="dots">...</small></var>)<var><a name="index-ezplot-961"></a></var><br> — Function File: <var>h</var> = <b>ezplot</b> (<var><small class="dots">...</small></var>)<var><a name="index-ezplot-962"></a></var><br> <blockquote> <p>Plots in two-dimensions the curve defined by <var>f</var>. 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>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> provides a list of handles to the the line objects plotted. <!-- 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> <!-- ./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-963"></a></var><br> — Function File: <b>ezcontour</b> (<var><small class="dots">...</small>, dom</var>)<var><a name="index-ezcontour-964"></a></var><br> — Function File: <b>ezcontour</b> (<var><small class="dots">...</small>, n</var>)<var><a name="index-ezcontour-965"></a></var><br> — Function File: <b>ezcontour</b> (<var>h, <small class="dots">...</small></var>)<var><a name="index-ezcontour-966"></a></var><br> — Function File: <var>h</var> = <b>ezcontour</b> (<var><small class="dots">...</small></var>)<var><a name="index-ezcontour-967"></a></var><br> <blockquote> <p>Plots 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> provides a list of handles to the the parts of the vector field (body, arrow and marker). <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> <!-- ./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-968"></a></var><br> — Function File: <b>ezcontourf</b> (<var><small class="dots">...</small>, dom</var>)<var><a name="index-ezcontourf-969"></a></var><br> — Function File: <b>ezcontourf</b> (<var><small class="dots">...</small>, n</var>)<var><a name="index-ezcontourf-970"></a></var><br> — Function File: <b>ezcontourf</b> (<var>h, <small class="dots">...</small></var>)<var><a name="index-ezcontourf-971"></a></var><br> — Function File: <var>h</var> = <b>ezcontourf</b> (<var><small class="dots">...</small></var>)<var><a name="index-ezcontourf-972"></a></var><br> <blockquote> <p>Plots 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> provides a list of handles to the the parts of the vector field (body, arrow and marker). <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> <!-- ./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-973"></a></var><br> — Function File: <b>ezpolar</b> (<var><small class="dots">...</small>, dom</var>)<var><a name="index-ezpolar-974"></a></var><br> — Function File: <b>ezpolar</b> (<var><small class="dots">...</small>, n</var>)<var><a name="index-ezpolar-975"></a></var><br> — Function File: <b>ezpolar</b> (<var>h, <small class="dots">...</small></var>)<var><a name="index-ezpolar-976"></a></var><br> — Function File: <var>h</var> = <b>ezpolar</b> (<var><small class="dots">...</small></var>)<var><a name="index-ezpolar-977"></a></var><br> <blockquote> <p>Plots in polar plot defined by a function. 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> provides a list of handles to the the parts of the vector field (body, arrow and marker). <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>