3
> y = [ 0.08 0.015 0.009 0.006 0.0055]
Entering the name of the variable retrieves its current values. For instance:
> x
> y
We can plot data in the form of vectors using the plot command:
> plot(x,y)
This will produce a graph with the data points connected by lines.
If you would prefer that the
data points be represented by symbols you can do so. For instance:
> plot(x,y,’*’)
> plot(x,y,’o’)
> plot(x,y,’.’)
Data as a Representation of a Function
A major theme in this course is that often we are interested in a certain function
y
=
f
(
x
), but
the only information we have about this function is a discrete set of data
{
(
x
i
, y
i
)
}
. Plotting the
data, as we did above, can be thought of envisioning the function using just the data. We will find
later that we can also do other things with the function, like differentiating and integrating, just
using the available data. Numerical methods, the topic of this course, means doing mathematics by
computer. Since a computer can only store a finite amount of information, we will almost always
be working with a finite, discrete set of values of the function (data), rather than a formula for the
function.
Built-in Functions
If we wish to deal with formulas for functions,
Matlab
contains a number of built-in functions,
including all the usual functions, such as
sin( )
,
exp( )
, etc..
The meaning of most of these is
clear. The dependent variable (input) always goes in parentheses in
Matlab
. For instance:
> sin(pi)
should return the value of sin
π
, which is of course 0 and
> exp(0)
will return
e
0
which is 1. More importantly, the built-in functions can operate not only on single
numbers but on vectors. For example:
> x = linspace(0,2*pi,40)
> y = sin(x)
> plot(x,y)