Unformatted text preview:

Lecture 2: Introduction to MathematicaLecture 2: Expressions and EvaluationGetting StartedExample 2-1: Basic Input and AssignmentExample 2-2: Building Expressions and Functions and Operations on ExpressionsExample 2-3: Calculus and PlottingExample 2-4: Lists, Lists of Lists, and Operations on ListsExample 2-5: Rules () and Replacement (/.); Getting HelpGetting Help on Mathematica3.016 HomeJJ J I IIFull ScreenCloseQuitcW. Craig CarterSept. 7 2012Lecture 2: Introduction to MathematicaExpressions and EvaluationThere are very many ways to learn how to use MathematicaR . Nearly all of the best ways involve performing examplesfrom the very beginning. That is how we are going to start—with examples. Using MathematicaR ’s FrontEnd you mayexecute a command by pressing Shift-Enter ; simply pressing Enter tells MathematicaR ’s that you merely wish to have a“carriage return” on the screen.Mathematica’s syntax will feel fairly natural after a while. Use the following notebook to get started. Execute a fewcommands until you get a sense for what output MathematicaR will produce; try editing the commands; try to makeMathematicaR do something strange—just try playing with it and you will soon get the hang of what is going on.One way to use MathematicaR is simply as a calculator that allows symbols to get carried along. MathematicaR willusually try to resolve every symbol and return precise information about it. If something is undefined to MathematicaR ,it simply returns it as a symbolic expression.A number is not returned until all of the symbols in an expression are defined as numbers. MathematicaR will try to beexact—it does not calculate13+12by adding 0.33333 · · · + 0.5 = 0.83333 . . ., it has an algorithm for adding rational numbersand gives56.Getting StartedThere are a variety of ways to get MathematicaR started and these are specific to the operating system your computeruses. A license must be purchased to run MathematicaR code, but free MathematicaR -display tools can be obtainedfrom Wolfram.3.016 HomeJJ J I IIFull ScreenCloseQuitcW. Craig CarterThe FrontEnd is the graphical interface between the user and MathematicaR —you arrange your MathematicaRinput, sometimes with text-like comments, in the FrontEnd. The user must request the FrontEnd to pass something toMathematicaR ’s kernel, by pressing Shift-Enter. The kernel is the resident symbolic algebra software engine behindMathematicaR .The appearance of the FrontEnd depends on either provided or user-designed StyleSheets. Style sheets can be located underthe Format menu.3.016 HomeJJ J I IIFull ScreenCloseQuitcW. Craig CarterLecture 02 MathematicaR Example 1Basic Input and Assignmentnotebook (non-evaluated) pdf (evaluated, color) pdf (evaluated, b&w) html (evaluated)The methods of assigning symbols (SomeVariable) to expressions via SomeVariable = expr. The expr can contain other symbolicvariables, functions, programs, graphics, and many other things. There are important differences between exac t (symbolic) objects andnumerical objects. Logical equalities (==) are not assignments, but are Boolean operations.Assigning values to symbols1a =4 p32UnitSphereVolume = a32 a4ANewVariable = H2 a + bL^ 25ANewVariable ^ 26b =4 H3.14159265358979L37UnitSphereNumericalVolume = b8ANewVariableDifferences between exact expressions and numerical expressions9UnitSphereVolume - UnitSphereNumericalVolume10a -4 ArcCos@-1D311a -4 [email protected] Pi - 2 H3.141519L13N@5 ê 6DDistinction between Equality (= = ) and Assignment (=)14a ã4 ArcCos@-1D315a ã4 H3.14159L31: A symbol is assigned to an expression with an equals sign =. Some symbols, such as π, are alreadydefined—in MathematicaR it is exactly the ratio of a circle’s circumference to its diameter. Here,a is a symbol that could represent, for example, the volume of a sphere with radius 1—and not anapproximation depending on how many digits are used to numerically represent π.2: In my opinion, the variable a is not a very go od name. We might forget what it represents, ortry to use it again in a different context. I think it is much better to use descriptive names,such as UnitSphereVolume. Here, because there is an assignment in UnitSphereVolume = a,MathematicaR tries to see if there are any other assignments associated with the right-hand-side, and if there are it uses them until all possible assignments have been made.3: Because no as si gnment was made to a just above, its value is not changed.4: The RHS in an assignment (here to ANewVariable) can contain unassigned symbols.6–7: Here, the symbols b and UnitSphereNumericalVolume are assi gned to an approximation to the unitsphere volume.8: Note that, because ANewVariable contains b, the assignment of b above is reflected in the currentval ue of ANewVariable: MathematicaR wi ll check to see if any symbol being output has beenassigned.9: To show the difference between the numerical approximation of π and the symbol π, subtractionshows that the difference i s a very very small number.10: Some functions can be have as exact if their values can be expressed exactly: here ArcCos[-1] isexactly pi.11: Notice that the output here is different, showing that ArcCos[-1.0] has been replaced with a numericalrepresentation because the function was executed on a numerical object.14: The operator == tests to see if the LHS (left-hand side) and the RHS (right-hand side) can bedetermined to be equal, in which case it returns true.15: If == can do so, it will return false if the two sides are not equal; otherwise if it can’t say whethertrue or false, it will just return the statement itself.3.016 HomeJJ J I IIFull ScreenCloseQuitcW. Craig CarterLecture 02 MathematicaR Example 2Building Expressions and Functions and Operations on Expressionsnotebook (non-evaluated) pdf (evaluated, color) pdf (evaluated, b&w) html (evaluated)Sometimes it is easier to build up complicated expressions by entering shorter subexpressions beforehand. There are usually many waysto do the same thing in MathematicaR , and this is demonstrated for functions. As you begin, pick the most simple method thatworks. Someday later you can pick up the alternative methods—they can be useful in advanced usage.Mathematica Functions1a = 1 ê Exp@xD2b = Cos@xD3c = Ha + bL ^ 2Alternative Syntax for Functions (There are many ways to do the same thing)4AnotherVersionofb = x êê


View Full Document
Download Lecture 2: Introduction to Mathematica
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 2: Introduction to Mathematica and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2: Introduction to Mathematica 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?