Lecture 1 - Introduction To Mathematica A

2y ago
18 Views
2 Downloads
1.97 MB
20 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Ronnie Bonney
Transcription

G562 Geometric MorphometricsMathematicaAn Introduction(c) Wolfram ResearchDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsProgramming, simple or complicatedUses for MathematicaCalculations, simple or complicatedMathematical functionsStatistical analysisDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsGraphics in MathematicaPlots of dataPlots of functionsDepartment of Geological Sciences Indiana UniversityThree-dimensional plotsSpecialized objects(c) 2012, P. David Polly

G562 Geometric MorphometricsGetting helpMathematica help files can be browsed orsearched from the Documentation Center ofthe Help menuFunction names are always made of upcomplete words, no spaces, with the first wordcapitalizedSearch for functions you hope exist:“Histogram”, “LinearRegression”,“PrincipalComponents”, “GenomeData”Note Function Browser and Mathematica Bookhelp buttons at top left of the DocumentationCenterLynda.com has three useful training coursesfor Mathematica 10 from Curt Frye (“Up andRunning”, “Essential Training”, “AdvancedAnalysis”). Access Lynda through one.iu.edu.Department of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsKernels and NotebooksMathematica has two components, thekernel and the notebookThe kernel is the invisible part of theprogram that does all the calculationsThe notebook is the main user interface,its purpose is to allow you to performanalyses and to save them for re-use orfor later referenceYou can work with many notebooks atonce. They share information betweenthem because they interface with thesame kernelFor advanced work you can work withtwo kernels, which allows you to run twosets of calculations in differentnotebooks at the same timeA typical Mathematica notebookDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsNotebooks and cellsNotebooks are organized into cellsDefault cells are for calculations, with input enteredby you followed by output created by the kernelCells must be executed to obtain output: Shift Enter toexecuteCells may be executed more than once, and the inputcan be changed between executionsBrackets in the right margin show cell boundariesand distinguish between input and outputUses for brackets:1. monitor calculations (bracket is highlighted while the kernel isexecuting)2. select entire cell for deletion3. hide output by double clickingDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsFormatting notebooksNotebooks can be formatted like a wordprocessor documentIndividual cells can be formatted as titles,text, section headings, or input (input isthe default)Notebook formatted with default stylesheetUse Format Style menu to formatindividual cellsUse Format Stylesheet menu to formatthe whole notebookNotebook formatted with pastel color stylesheetDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsFunctionsFunctions are key to Mathematica: functions receive information or data,process it, and return a resultFunctions are called by their name, usually composed of complete Englishwords describing what the function does, with no spaces and first letterscapitalizedFunction names are followed by square brackets, in which one or morearguments is entered:FunctionName[argument]For example, the ListPlot[] function takes a matrix of x,y values as itsargument:ListPlot[{{1,2},{3,4}}]Mathematica’s help files give descriptions and examples of every functionDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsListplot with no optionsOptions for functionsMany functions have options that areentered as argumentsOptions usually have the formatOptionName - ValueFind options with Options[FunctionName]or in Documentation CenterDepartment of Geological Sciences Indiana UniversityListplot with three options(c) 2012, P. David Polly

G562 Geometric MorphometricsVariablesVariables are also key to Mathematica,allowing you to store informationVariables do not have brackets or optionsYou create variables, giving them a nameand putting something into themHere a variable called data is used to storea number, a sequence of numbers, thenatural log of a sequence of numbers, anddata imported from an Excel file. Avariable called mygraph is used to store agraphicYou can retrieve what is inside a variableby executing it (the graph is displayedagain by executing mygraph)Department of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsParts of variablesWhen a variable has more than one itemstored, you can get specific parts usingdouble square brackets after the variablenamedata returns all the items in datadata[[1]] returns only the first item in datadata[[1;;3]] returns items 1 to 3For more examples look at theDocumentation Center under the functionPart[] and under the tutorialGettingPiecesOfListsDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsLists, Matrices, and other Multidimensional dataYou will often work with “lists”, which isMathematica’s term for any group ofseveral itemsSome lists have only one element (scalar),some have a long row of elements (vector),some have columns and rows of data(matrix or array)You can get columns, rows, or elementsfrom the list using the double squarebracket systemSee Documentation Center under:1. ListsOverview2. HandlingArraysOfDataDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsSpecial formatting tagsYou can control the display of output inmany ways by putting special tags at theend of a line of inputsemicolon (;) prevents output from beingdisplayed//N forces numbers to be displayed indecimal form//MatrixForm displays tables of data inrows and columnsDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsImporting and exporting dataMathematica has an extensive range offile types that can be imported andexported: text files, Excel files, Word files,PDFs, Illustrator, JPEG, etc.Import[FilePath]Export[FilePath, “type”]Note the helpful file path chooser found onthe Insert menuDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsSimple tment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsLoops: programming structure for repeating thingsUse Table[], Map[], or Do[] to carry outrepeated tasksTable[ lines to be repeated , {iterator}]where the lines to be repeated consist ofother Mathematica functions or lists offunctions separated by semicolonsiterator is a special construction thatcreates a temporary counting variable andspecifies number of times to repeatSimple: {10} (repeats 10 times)With variable: {x,10} (repeats while incrementing xfrom 1 to 10 in steps of 1)Full: {x,1,10,1} (repeats while incrementing x from1 to 10 in steps of 1)Full: {x,10,2,-2} (repeats while incrementing xbackward from 10 to 2 in steps of 2)Department of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsConditional statementsIs equal? Is unequal?! Greater than? Less than? And&&Or If[ statement is true, then this, or else this ]myage 65.5;If[ myage 50, Print[“my age is older”], Print[“my age is not older”]If[ myage 55 && myage 65, Print[“my age is in the bin”], Print[“my age isoutside the bin”]Department of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsWorking with StringsStrings are entities of characters, as opposed to numbers. You canmanipulate strings in Mathematica as well as numbers. For example:mytext “Species”;You can combine strings by joining them with the StringJoin[] function or (which do the same thing):You can create a list of labels using Table[] and ToString[], the latter of whichconverts numbers to strings so they can be joined to other strings:Department of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsIn[14]: ListPlot@Table@RandomReal@80, 1 , 2D, 81000 DD1.0Random numbersMathematica has many functions forgenerating random numbers.0.80.6Out[14] 0.4H* Random real number from 0 to 1 *LIn[4]: Out[4] RandomReal@D0.9513H* random real number from 100 to 1000 *LIn[5]: Out[5] 0.20.20.40.60.81.0RandomReal@8100, 1000 D505.785H* 10 random real numbers from 100 to 1000 *LIn[10]: Out[10] RandomReal@8100, 1000 , 10D8178.469, 576.318, 234.461, 549.177, 178.544, 581.808, 823.167, 515.409, 828.69, 951.191 H* Random number drawn from a normal distribution with a mean of 10 and standarddeviation of 100 *LIn[11]: Out[11] Random@NormalDistribution@10, 100DD154.744H* 10 pairs of random numbers between 0 and 1 *LIn[12]: Out[12] Table@RandomReal@80, 1 , 2D, 810 D880.0245927, 0.630284 , 80.260035, 0.591502 , 80.38211, 0.146923 ,80.891077, 0.0315945 , 80.75184, 0.567132 , 80.553506, 0.443656 ,80.614652, 0.300159 , 80.791076, 0.0654448 , 80.19977, 0.272843 , 80.291167, 0.958036 Photo creditDepartment of Geological Sciences Indiana University(c) 2012, P. David Polly

G562 Geometric MorphometricsModule function(closes after theReturn function)Defining your own functionYou can create your own customizedfunctions to perform operations that youuse a lot.The syntax uses “: ” to define theoperation of the function.Function nameInput parametersIn[17]: MyFunction@x , y D : Module@8i, j ,i 10;j i * Hx yL;Return@jD;DIn[18]: MyFunction@1, 2DThe input parameters are defined asvariables with an underscore after them.The Module function shields the variablesused in the custom function from the restof the notebook (it keeps them fromclashing).Custom functions usually end with Return,which is a function that returns somethingto the user in response to the inputparameters.Department of Geological Sciences Indiana UniversityInternalvariablesOut[18] 30This example takes two numbers asinput, adds them together andmultiplies them by 10, and storesthe result in the temporary internalvariable j. The value is returned tothe user at the end of the function.(c) 2012, P. David Polly

A typical Mathematica notebook Kernels and Notebooks Mathematica has two components, the kernel and the notebook The kernel is the invisible part of the program that does all the calculations The notebook is the main user interface, its purpose is to allow you to perform analyses and to save them for re-use or for later reference

Related Documents:

1 Mathematica Basics This chapter is an introduction to Mathematica.We briefly describe many of the most important and basic elements of Mathematica and discuss a few of the more common technical issues related to using Mathematica.Since our primary goal is to use Mathematica to help us understand calculus, you should not initially spend a great amount of time pouring

Introduction.NET/Link Welcome to .NET/Link, a product that integrates Mathematica and Microsoft's .NET platform.NET/Link lets you call .NET from Mathematica in a completely transparent way, and allows you to use and control the Mathematica kernel from a .NET program. For Mathematica users,.NET/Link makes the entire .NET world an automatic extension to the Mathematica environ-

Introduction of Chemical Reaction Engineering Introduction about Chemical Engineering 0:31:15 0:31:09. Lecture 14 Lecture 15 Lecture 16 Lecture 17 Lecture 18 Lecture 19 Lecture 20 Lecture 21 Lecture 22 Lecture 23 Lecture 24 Lecture 25 Lecture 26 Lecture 27 Lecture 28 Lecture

Online Help from Mathematica 2 Mathematica Tutorial.nb. Introduction Mathematica is a system for doing mathematics on the computer.It can do numerics,symbolics,graphics and is also a programming language.Mathematica has infinite precision.It can plot functions of a single variable; make

Dec 09, 2005 · Beginner’s Mathematica Tutorial Introduction This document is designed to act as a tutorial for an individual who has had no prior experience with Mathematica. For a more advanced tutorial, walk through the Mathematica built in tutorial located at Help Tutorial on the Mathematica Task Bar.

mathematica Remarks This section provides an overview of what wolfram-mathematica is, and why a developer might want to use it. It should also mention any large subjects within wolfram-mathematica, and link out to the related topics. Since the Documentation for wolfram-mathematica is new, you may need to create initial versions of those related .

PROGRAMMING IN MATHEMATICA, A PROBLEM-CENTRED APPROACH 7 1.3. Algebraic computations. One of the abilities of Mathematica is to handle symbolic com-putations. Consider the expression (x 1)2. One can use Mathematica to expand this expression: Expand[(x 1) 2] 1 2x x2 Mathematica can also do the inverse of this task, namely to factorize an expression:

Start up Mathematica from a Linux desktop terminal window. Parallel Mathematica jobs can be submitted from with the Mathematica notebook interface as well as using PBS command files and the example scripts show how to setup and submit the jobs Documentation:Submitting Mathematica Parallel Jobs (UVACSE) October 8, 2014 44 / 46