Mathematics Previous page   Next Page

Plotting Mathematical Functions

The fplot function plots a mathematical function between a given set of axes limits. You can control the x-axis limits only, or both the x- and y-axis limits. For example, to plot the humps function over the x-axis range [-5 5], use

You can zoom in on the function by selecting y-axis limits of -10 and 25, using

You can also pass the function handle for an anonymous function for fplot to graph, as in

You can plot more than one function on the same graph with one call to fplot. If you use this with a function, then the function must take a column vector x and return a matrix where each column corresponds to each function, evaluated at each value of x.

If you pass an anonymous function consisting of several functions to fplot, the anonymous function also must return a matrix where each column corresponds to each function evaluated at each value of x, as in

which plots the first and second functions on the same graph.

plot of the first and second functions on the same graph

Note that the anonymous function

evaluates to a matrix of two columns, one for each function, when x is a column vector.

returns


Previous page  Representing Functions in MATLAB Minimizing Functions and Finding Zeros Next page

© 1994-2005 The MathWorks, Inc.