A Brief Introduction To Mathematica - C.Moretti.pdf

(969 KB) Pobierz
Text Master
A Brief Introduction To Mathematica
Dr. Christopher Moretti
Department of Mathematics
Southeastern Oklahoma State University
Mathematica is a registered trademark of Wolfram Research, Inc.
1
TABLE OF CONTENTS
Page
Chapter One - Getting Started ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3
Section One - Starting Mathematica :::::::::::::::::::::::::::::::::::::::::::::::::::: 3
Section Two - Input and Output ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3
Section Three - Brackets and Braces ::::::::::::::::::::::::::::::::::::::::::::::::::: 5
Section Four - Exact and Approximate numbers and Built-in Constants ::::::::::::::::: 5
Section Five - Loading in Additional Packages :::::::::::::::::::::::::::::::::::::::::: 5
Chapter One Exercises ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7
Chapter Two - Mathematical Functions ::::::::::::::::::::::::::::::::::::::::::::::::::::: 8
Section One - Built-In Functions ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 8
Section Two - De¯ning Functions and Equalities :::::::::::::::::::::::::::::::::::::: 10
Chapter Two Exercises ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 12
Chapter Three - Lists and Matrices :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 13
Section One - Lists ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 13
Section Two - Generating Lists :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 13
Section Three - Functions Involving Lists :::::::::::::::::::::::::::::::::::::::::::::: 14
Section Four - Displaying Tables and Matrices ::::::::::::::::::::::::::::::::::::::::: 15
Section Five - Plugging Into Expressions :::::::::::::::::::::::::::::::::::::::::::::: 15
Chapter Three Exercises :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 17
Chapter Four - Mathematica and Algebra ::::::::::::::::::::::::::::::::::::::::::::::::: 18
Chapter Four Exercises ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 19
Chapter Five - Solving Equations :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 20
Chapter Five Exercises :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 22
Chapter Six - Calculus :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 23
Section One - Limits :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 23
Section Two - Derivatives ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 23
2
Section Three - Integrals :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 25
Section Four - Series :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 26
Section Five - Di®erential Equations :::::::::::::::::::::::::::::::::::::::::::::::::: 27
Chapter Six Exercises ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 29
Chapter Seven - Linear Algebra ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 30
Chapter Seven Exercises :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 32
Chapter Eight - Two-Dimensional Plots ::::::::::::::::::::::::::::::::::::::::::::::::::: 33
Section One - Basic Plots ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 33
Section Two - Plot Options ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 33
Section Three - Parametric Plots :::::::::::::::::::::::::::::::::::::::::::::::::::::: 37
Section Four - Plotting the Graphs of Equations ::::::::::::::::::::::::::::::::::::::: 38
Chapter Eight Exercises :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 39
Chapter Nine - Three-Dimensional Plots ::::::::::::::::::::::::::::::::::::::::::::::::::: 40
Section One - Basic 3-D Plots ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 40
Section Two - Plot3D Options :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 41
Section Three - Parametric 3D Plots :::::::::::::::::::::::::::::::::::::::::::::::::: 45
Chapter Nine Exercises ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 48
Solutions to Exercises ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 49
3
Chapter One - Getting Started
Section One - Starting Mathematica
To launch the Mathematica application, open its folder and double-click the Mathematica icon.
This will launch the portion of Mathematica known as the front end.
Mathematica is split up into two pieces - the front end and the kernel.
The front end is where you enter commands and where the results are displayed (be they plots,
functions, whatever). The front end is similar to a word processor - it has no mathematical abilities
itself, but it can open, save, and display Mathematica ¯les (called notebooks). You do all of your
work in the front end.
The kernel is where all of the mathematical computation is done. You never actually see the
kernel at work (unless you open a special window to do so), even though that's where the real work
is being done.
Mathematica is split up this way to conserve computer resources - especially computer memory.
Mathematica's kernel is very powerful and can tax older computers. Since the front end is separate
from the kernel, you can use the front end to enter things and view previous work without taxing
the computer. When you double-click the Mathematica icon, it launches the front end. The kernel
isn't launched until you try to evaluate your ¯rst expression.
Section Two - Input and Output
In the front end, information is grouped into \cell". A cell includes both the input and the
output that is generated it by it. Cells are grouped together by square brackets on the right-hand
side of the front end's window. To evaluate a cell (that is, have Mathematica process it), make
sure your cursor is somewhere in the input portion of the cell (usually the topmost bracket in
the grouping) and hit shift-enter (Windows) or enter (Macintosh). Throughout this text I will
mention \entering" a command, or \using" or \running" a command. All of these mean putting
the command into a cell and then evaluating the cell.
Once evaluated, each command you input (and you can have more than one in a cell) and its
result are assigned numbers so you can refer to them later - the k-th command you enter is labeled
In[k] and its output as Out[k]. For example, type 1+3 in a cell and evaluate it. You should see the
4
input and output numbers on the left side of the front end's window. In a new cell, type the output
number (if it was Out[2], then type Out[2] in the new cell) and then evaluate the cell. You should
get 4 again, since Mathematica knows you're referring to the previous calculation. Mathematica
does not go through all the work the second time, it just repeats the output - which can save a lot
of time if the calculation you're skipping was complex. You don't have to just repeat the previous
output, you can use it in a new calculation - if you enter 5*Out[2] and evaluate (assuming Out[2]
was the number 4 from before), then Mathematica will return 20.
Another way to refer to previous input is through percent signs. Entering % in Mathematica
is short-hand for \the last output you gave me". So if the last output was 8128, if you evaluate a
cell with % in it you will get 8128. If you had entered %-5, you would get 8123. So the percent
sign is a good way to quickly refer to your previous calculations without a lot of retyping (or a lot
of cutting-and-pasting). You can even refer to outputs farther back by using more percent signs,
like %% and %%%. If the last three outputs were x 2
¡
2 x + 1, 3x, and 5, then if the very next cell
you evaluate is %%% Mathematica will return x 2
¡
2 x + 1. One thing you do need to be careful
about is that the percent signs always work in chronological order. If you do 50 calculations in
a notebook and then create a new cell all the way at the top (by clicking the mouse before the
¯rst cell and starting to type) with %%, the result will still be the 49th (second to last) output.
Another thing to be careful of is that if you save a notebook and quit Mathematica, it forgets all
of the previous input and output - both in the In[ ]/Out[ ] format and with percent signs. When
you reopen the notebook you will have to go back and reevaluate the necessary cells the next time
- and if you are using percent signs, you have to do it in the same order too. So if you are going to
be saving your work to disk, retyping output or using copy and paste is not a bad idea.
There is another output trick which occasionally comes in handy. Sometimes you may want
to do a calculation (maybe expanding ( x +1) 1000
or doing a complex 3-D plot) and not want to
see the output because it would be too long or Mathematica is low on memory. If you end the
input with a semi-colon Mathematica will process the input but won't print the output. You can
still refer to it by Out[42] or %%% - it just won't be on the screen. So if you evaluate a cell with
Expand[( x +1) 1000
¡
x 1000 ]; Mathematica will still process it, but the output (which would be
several screens long) won't appear to clutter your work.
Zgłoś jeśli naruszono regulamin