Graphics Programs Reference
In-Depth Information
Note that
^
has been replaced by
.^.
Now you can evaluate
f1
on a vector:
>> f1(1:5)
ans =
3
7
13
21
31
You can plot
f1
, using MATLAB graphics, in several ways that we will explore
in the next section. We conclude this section by remarking that one can also
define functions of two or more variables:
>> g = inline('uˆ2 + vˆ2', 'u', 'v')
g=
Inline function:
g(u,v) = u^2+v^2
Graphics
In this section, we introduce MATLAB's two basic plotting commands and
show how to use them.
Graphing with
ezplot
The simplest way to graph a function of one variable is with
ezplot
, which
expects a string or a symbolic expression representing the function to be plot-
ted. For example, to graph
x
2
+
x
+
1 on the interval
−
2 to 2 (using the string
form of
ezplot
), type
>> ezplot('xˆ2+x+1',[-22])
The plot will appear on the screen in a new window labeled “Figure No. 1”.
We mentioned that
ezplot
accepts either a string argument or a symbolic
expression.Usingasymbolicexpression,youcanproducetheplotinFigure2-4
withthe following input:
>> syms x
>> ezplot(xˆ2+x+1,[-22])
Graphs can be misleading if you do not pay attention to the axes. For
example, the input
ezplot(xˆ2+x+3,[-22])
produces a graph
Search WWH ::
Custom Search