Excel graphs. With
some data in cells, click on the "insert" button on the top menu.
One of the options will be to create a chart. You can highlight
data and put it in the chart.
If you click on the "insert" button at the top of the page you'll see
"functions". There are LOTS of these! Trig, stat, database,
financial, etc. So you can have a bunch of data points and then
plot these after using various stat or trig functions on them.
--------------------------------------------------------------------------------------------------
MATLAB & Python
These are two "scripting" languages that you can
use.
start menu -> programs -> math & statistics software ->
MATLAB (maple is also here)
start menu -> programs -> faculty requested -> Python 2.5
-> IDLE Python GUI
Matlab is designed primarily for numeric computation and visualization,
Python is a more general-purpose language. Both let you start
doing things quickly, but both have plenty of power as well.
------------------------------------------------------
We'll start with Matlab. Fire it up by following the path
above. The large right window is where you'll do most of the
work. You'll normally see a ">>" prompt. After this
prompt, type in 23+99+12 and hit the return key. Matlab responds
with
ans =
134
In this example, you're just using Matlab as a kind of a desk
calculator. Now at the prompt type in
valueA = 15
Matlab responds with
valueA =
15
(Note that Matlab, like UNIX, is very case-sensitive, and it doesn't
like blanks in names)
Type valueB = 27
Then type valueC = valueA + valueB [watch
what's going on in the lower left window]
valueA, valueB, and valueC are what are called variables.
A variable does not have a fixed value. Think back to when your
teacher had you work with expressions X = 2*Y -5*Z.
You could plug in values for
Y and Z and this would determine the value of X. On the other
hand, in that same expression, the 2 and the 5 are fixed values--these
are not variables--their values never (we hope!) change. To help
see this, type valueA = 2, then type valueC = valueA + valueB.
You'll see that what's in the variable valueA has changed--it used to
be 15, but now it's value is 2.
------------------------
standard math symbols== a+b a*b a-b
a/b a^b [this is a to the bth power]
base conversion: try typing valueD= dec2hex(valueC)
this converts what was in valueC to hexadecimal, and stores it in
valueD. Now just type valueD
You'll see that valueD has retained the value in hex.
Some built-in functions: valueE = sqrt(valueC) gets the
square root of the value of valueC.
Y = sin(X)
this gets the sine of X, in radians.
Y_degree =
Y*180/pi converts
radians to degrees.
------------------------------------------------------------------------
ARRAYS: simple variables hold a single value--a name, an integer,
a floating-point such as 3.14159, etc.
An ARRAY holds a bunch of values [it is possible to have an array with
only one value, but we will not worry about that here] For
example, we might want a list of all NetIDs for Bridge students, or an
array of data values from running a physics experiment.
>>x=[0,1.4,1.95,-0.02,37.8,14.4] creates an array with 6
data values. Try this in Matlab and see what happens:
Matlab lists all the data values. If you need a particular value,
or want to change a value in the array:
>>x(1)
ans =
0
So legal subscripts are x(1), x(2), x(3), x(4), x(5), and x(6)
here. [a word of warning: most programming languages
nowadays would have the array's first value as x(0), not x(1), and the
last would be x(5), not x(6).
You can multiply your array by a value:
>>x*pi [pi is a built-in constant, 3.14159etc]
Try this and see what happens.
Typing in all an array's values can be tedious--imagine you need data
points at 0.0, 0.01, 0.02, ..0.99--that's 100 data values. Matlab
has some convenient ways of creating arrays.
>>x=(0.0:0.1:0.9) would tell Matlab to create an array with
10 elements--start with 0.0, increment by 0.1 each time, continue until
you reach 0.9. So >>x=(0.0:0.01:0.99) would have created
the array described previously where we wanted 100 elements.
>>x=linspace(0.0,0.99,100) does the same thing--this tells Matlab
to create an array with 100 elements, starting at 0.0, and finishing at
0.99. NOTE: linspace(0.0,1.0,100) produces a different
array--why? Try it!
--------------------------------------------------------
PLOTTING AND VISUALIZATION
Try the following:
>>x=linspace(0,2*pi,30);
[the ";" tells Matlab not to display the result here]
>>y=sin(x);
>>plot(x,y)
this draws a nice sine curve.
now add
>>z=cos(x);
>>plot(x,y,x,z)
two curves!
now try
>>plot(x,y,'+')
this puts a "+" symbol at each data point--
>>plot(x,y,x,y,'+')
this draws the data points, but with a smooth line through them
>>plot3(y,z,x),grid
NOTE: this is plot3, not plot. This gives a 3-D plot.
----------------------------------------------------------------------------------
>>f = inline('1/x - (x-1)')
this defines a function for you: f(x) = 1/x - (1-x)
ezplot is a variation of plot--it picks coordinates and tries to be
helpful.
to plot the function f above from 0 to 4:
>>ezplot(f,0,4)
-------------------------------------------
Polynomial roots
>>p = [1,-12,0,25,116] creates an array
If we say
>>r=roots(p) we're telling Matlab that p is a polynomial
x^4 -12x^3 + 0x^2 + 25x + 116
and we want to see the roots. Matlab tells us
r =
11.7473
[real root]
2.7028
[real root]
-1.2251 +
1.4672i
[imaginary root]
-1.2251 +
1.4672i
[imaginary root]
If you're skeptical, consider the simple equation x^2 + 1 =
0 (x squared + 1 equals 0)
To find the roots--we're looking for the zeroes of the polynomial
x^2 +0x + 1
so:
>>p = [1,0,1]
r=roots(p)
r =
0 + 1.0000i
0 - 1.0000i
--------------------------------------------
Matlab also has a wide variety of other tools--working with vectors,
matrices, derivatives, integrals, etc, along with visualization that
goes beyond plot, plot3, and ezplot. Matlab isn't a
general-purpose programming language: Doom IV is not written in
Matlab. But if you want a scientific tool it's fine.