Matlab is one of the most commonly used scientific
To start it, click (or double click) the Matlab icon.
To finish a Matlab session, type "quit"
at the prompt in the Matlab window.
Matlab interprets expressions you type in.
B^2 (this is squaring)
A/C would produce an error: C has not been
defined. If you don't assign the result of an expression to some
variable name (like A or B above), then it is assigned to the
variable ans. If you don't want to see the result
of a command on the screen, end the line with a semicolon (;)
assigns the result to a variable
C, but doesn't tell you what it is. You can see it with the command
Other functions available include
exp, log, sin, cos, tan,
atan, acos, the last two
being inverse functions (inverse tangent, inverse cosine).
The basic variable in Matlab
is the array, meaning a list of numbers, not a single number.
You can create an array with a single command, for example
makes the variable x
the array [1 2 3 4 5 6 7 8 9 10]. The command
makes the variable y
the array [1 4 9 16 25 36 49 64 81 100]. This is just each one
of the x's squared. (Note the '.' before the '^' in the command
to square each element of the x array.) Now
plots the squaring function.
You need not take x to be just integers. The command
takes values from 0 to 10 equally
spaced (linearly spaced), and 101 of them in all. This
means x is the array [0 0.1 0.2 0.3 ... 9.8 9.9 10.0].
(This might have been a good time to end the line with a semicolon
-- no need to see all those x's.) Now
plots the squaring function,
but with more values. The graph will be in green because of the
'g'. Try also things like
A Matlab Exercise
We have talked about a number
of functions. Let us see them graphically, and try to understand
the graphs. Sometimes the insight we get from general arguments
makes it easier to interpret the graphs, other times the graphs
themselves may give us insight we had not thought of.
Verify that you can get exponential
functions with different bases by trying out the commands
Try the following
commands to see exponential growth and decay:
It is best to enter these
in EXACTLY the order I have given, so that everything will be
visible. Why do you get a warning message when you plot x^(-1)?
What can you observe about the various powers and their relative
importance in this graph?
In class we looked briefly
at the polynomial P(x)=3x^3+2x^2-x+1. Graph it with
As we mentioned, near x=0
the important terms are -x+1, a linear function. Since
P(x) is essentially just this linear function near x=0, that must
be the equation of the tangent line. See this by first
of all "holding" the plot, so you can overlap two graphs,
then graphing the tangent line:
You can see that P(x) is very
nearly this linear function, at least for a small region near
Exponentials and powers
Exponentials decay faster
than powers grow, and grow faster than (reciprocal) powers decay
-- all remarks that apply as x gets large. Observe this, on the
positive x-axis, with
What is being illustrated
Here is a rather tricky challenge:
graph the rational function (x^2+3)/(x-1) in such a way that its
main features can be seen. We sketched a graph in class, but you
may find it hard to get a machine -- either Matlab or a graphing
calculator -- to do it well. Some possible tricks: plot(x,y,'+')
just plots points (as +'s), but does not connect them. You can
still see the shape of the function, and it may actually look
better. You can remove values of x from the domain -- say x(21),
x(22), x(23) -- with the command
The effect is to throw away
those values, and renumber what is left, so that there are fewer
x values. You may want to do that for values of x which are too
close to the singularity at x=1, where the denominator is zero.