Mathematica Bootcamp

2y ago
67 Views
18 Downloads
415.59 KB
37 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Pierre Damon
Transcription

Mathematica Bootcamp A.J. HildebrandContents1 Getting Started1.1 First steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2 Working with Mathematica Notebooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.3 Additional resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44452 Mathematica Basics2.1 Top things to know about the Mathematica Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . .2.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6663 Lists, Random Functions, and Random Walks3.1 Generating Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3.2 Generating random numbers and lists of random numbers . . . . . . . . . . . . . . . . . . . . . . . .3.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101011124 Functions, and Random Simulations4.1 Defining a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.3 Random Simulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .151517185 The5.15.25.3Map Command21Map in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Plotting and Interactive Visualization6.1 Plotting functions with Plot and Plot3D . . . . . . . .6.2 Plotting lists with ListPlot and ListLinePlot . . . . .6.3 Creating interactive animations with Manipulate . . . .6.4 Creating plots with Mathematica’s Graphics command.26262727287 Series and Asymptotic Expansions307.1 Series Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 Tips, Tricks, Shortcuts, and General Advice338.1 Writing code efficiently and quickly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338.2 Avoiding common mistakes and pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338.3 Learn and practice good coding habits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 Tutorials, Books, and9.1 Online Tutorials .9.2 Free E-Books . . .9.3 Other resources. .Further Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37373737 Notes from a Computational Bootcamp held May 30 – June 1, 2018, at the University of Illinois, as part of the University’sPI4 program. Funding provided by National Science Foundation grant DMS 1345032 MCTP: PI4: Program for Interdisciplinary andIndustrial Internships at Illinois. I thank John Haug, TA for the Bootcamp, for assistance with preparing these notes.1

CONTENTSMATHEMATICA BOOTCAMPAbout the BootcampThis Mathematica Bootcamp is based on a series of workshops I have developed for summer REU programs duringthe past three years. Most participants in these programs had no knowledge of Mathematica at the outset; a fewhad some basic familiarity with Mathematica, e.g., through courses, research projects, or NetMath. By the end ofthe program, all had attained a high level of proficiency in Mathematica, and several of the participants createdinteractive visualizations that have been published at the Wolfram Demonstrations website.1These workshops are aimed both at novices to Mathematica, and at those with some basic knowledge ofMathematica. The goal of these workshops is for you to: Develop a solid general foundation in Mathematica. Get familiar with the structure and syntax ofMathematica, learn how to do common tasks in a wide range of areas of mathematics, and get a taste of thepower and elegance of Mathematica. Develop in-depth knowledge of applications in selected areas. We will focus on topics relevant forthe PI4 program, such as series expansions and asymptotics. Develop and practice good coding skills. Learn useful tips and tricks, and learn to avoid commonmistakes and pitfalls. Learn how to use Mathematica as a tool for research. You’ll learn how to use Mathematica efficientlyto perform large scale numerical/visual experimentation, and to use such experimentation to discover/guessnew results.Format. Each workshop will be about two hours long and focus on a particular topic, e.g., Mathematica basics,lists, functions, graphics. The first hour or so of each workshop will consist of a presentation that you can followalong. In the second hour you will do exercises and a project, while I will be circulating through the room toprovide individual help. In the projects you will learn how to use Mathematica as a tool for research. You’ll useexperimentation and visualization with Mathematica to come up with conjectures and discover new results.Course materials. There will be a handout accompanying each workshop that includes the exercises and theproject, highlights some key points, and provides tips and advice on developing good coding habits and avoidingcommon mistakes and pitfalls.Course materials will also be made available through a U of I Box folder. If you have not used Box (throughthe U of I interface) before, you may need to set up an account first. Go to http://box.illinois.edu, and clickon “Sign up”.1 To see these, go to demonstrations.wolfram.com, and type any of the following names into the search box: Narken Aimambet,Chingis Matayev, Khoa Tran, Laila Zhexembay, Jose Sanchez, Madina Bolat, Daniyar Omarov.Version 2018.06.012A.J. Hildebrand

CONTENTSMATHEMATICA BOOTCAMPHow to get the most out of the workshops Try to work with your neighbor(s) and help each other out in case one ofyou gets stuck. Those new to Mathematica. Follow the presentation, using the accompanyingMathematica notebook to try things out yourself and get comfortable with the basicsyntax of Mathematica, and with working with notebooks. Try making small changesto the commands, and observe the output; use this opportunity to see what works,and what doesn’t, and try to learn from errors. Next, do the exercises on the handout(after opening up a new notebook), and finally try the projects. Those with prior knowledge of Mathematica. If you are already familiar withthe topic covered, do only selected exercises (e.g., pick one or two from each type),then move on to the projects. Focus on developing good coding habits, and unlearningany bad habits you may have acquired (such as using “For” or “While” loops inMathematica .). Carefully read all of the tips/tricks/advice sections on the handouts. Thesesections focus on the most important points and the most common sources of errors,and they help you develop good coding habits and guard against mistakes. Payparticular attention to the boxed/highlighted sections of the handout; theseinclude some of the most useful tips. After the workshop, finish any left-over exercises/projects, review thehandouts, and continue practicing Mathematica on your own. Mathematica is available on the computers in 239 Altgeld, and in the graduate student officesand labs in Altgeld and Coble Hall, and on all machines in the Illini Union lab andother University computer labs. If you want to use Mathematica on your own laptop,you can download an inexpensive version (and free for faculty/staff) from suggestions. If you have questions about the material of the workshop, just ask duringthe workshop.I’d be happy to assist with any Mathematica-related problems you encounter after the workshop (e.g. in yourPI4 research). I will be on campus through mid/late July; just email me at ajh@illinois.edu.I welcome comments and suggestions about these notes; email me at ajh@illinois.edu.Version 2018.06.013A.J. Hildebrand

1GETTING STARTED1MATHEMATICA BOOTCAMPGetting Started1.1First steps1. Find Mathematica on the computer and open it. All computers in 239 Altgeld have Mathematicainstalled; look for the orange “spikey” icon. If you want to use Mathematica on your own laptop, you caneither download a free 15 day trial version from Wolfram, wolfram.com or purchase a student version throughWebstore, webstore.illinois.edu ( 35 per semester for students, free for faculty/staff).2. Open a Mathematica Notebook. A Mathematica Notebook is where you do all of your work. Open a newnotebook, by clicking on “New Document”, then “Notebook.” In addition, you might want to download andopen the notebook accompanying this workshop using the “Open” tab. (Access will be provided to registeredparticipants.)3. Follow along the class presentation and do the exercises for the first workshop (see the section“Mathematica Basics” below).1.2Working with Mathematica Notebooks: Tips and Tricks1. Increase the magnification in your notebook to 125% (or larger), to make the text more readable(see the button on the lower right corner of the window). This makes it easier to distinguish betweendifferent types of parentheses, especially, e.g., curly braces {} and square brackets [], a common source oferrors.2. Press Shift-Enter after each command to evaluate this command and generate its output.Pressing Enter doesn’t do anything; also, a semi-colon (;) at the end of the command has the effect ofsuppressing the output instead of showing the output. (Occasionally, e.g., with commands that generatehuge amounts of output, this may be desirable, but normally you want to see the output.) To evaluate (orre-evaluate) all commands in a notebook, click on the “Evaluation” tab, then select “Evaluate Notebook.”3. Save your work frequently. Click on “File”, then “Save”. As you are learning Mathematica, you willmake frequent mistakes, and some of these may cause Mathematica to crash. If you are using one of thelab computers, email the notebook file to yourself at the end of each session so you have itavailable the next time.4. Dealing with freezes and crashes. If Mathematica gets “stuck” (e.g., because a calculation takes too long),click on “Evaluation”, then “Abort Evaluation.” Sometimes, it takes several tries to “kill” an evaluation.Occasionally, it doesn’t work at all, and Mathematica ends up crashing . Hence the advice to frequentlysave your work.5. Selecting, copying/pasting, and deleting material. A notebook is organized into cells, either aninput cell (indicated by In[.] .) or an output cell (indicated by Out[.] .). Each cell has anaccompanying bracket on the right side of the window. To select the cell, click on this bracket. You can usethe Edit menu to delete/cut, or copy the cell. For example, if a calculation inadvertently generated largeamount of output, you can delete the output cell using this technique.6. Text entry vs. visual entry of symbols. Under the “Palettes” tab Mathematica provides an options toenter mathematical notation (e.g., squareroots, fractions, exponents, or mathematical constants π, e, i, etc.)by picking appropriate symbols from a palette, instead of typing in the corresponding text version. You are,of course, free to do this if you want, and some tutorials will teach you this, but my advice is to not botherwith the palette:TIP: Don’t bother with palettes, and things liks Math Assistant, Class Assistant, etc. Formathematical symbols and special letters just type in the appropriate text equivalent: Pifor π, Sqrt for a squareroot, a/b (with a forward slash) for the fraction ab , a b for the powerab , etc. Hunting for symbols in a palette will only slow you down, and you’ll have know thetext equivalents anyway in order to be able to read code others have written.Version 2018.06.014A.J. Hildebrand

1GETTING STARTEDMATHEMATICA BOOTCAMP7. Getting help. Click the Help tab to open access the Mathematica Documentation. If you don’t know howto do something in Mathematica use the search function in the Documentation to find appropriate help pages.Particularly useful are the sections “See Also” and “Tutorials” near the bottom of each help page.TIP: Keep a documentation window open at all times, so you can access it if needed.8. Quick access to help pages. To get the documentation for a particular command, start typing thecommand until a circled “i” symbol pops up. Alternatively, you can slowly move your mouse through thecommandname from left to right until the circled “i” symbol pops up. Clicking on this symbol will pop up awindow with the documentation page for this command.TIP: Use built-in documentation rather than searching online. The built-in documentation(accessed through the “Help” tab in a Notebook window, or by clicking on a circled “i” as described above) gives more reliable information and is specific to the particular Mathematicaversion you have installed.1.3Additional resourcesFor those with prior programming experience, I recommend the tutorial Fast Introduction for Programmers,available at www.wolfram.com. (Just type the title, ”Fast Introduction”, into the search box.) This is a shortinteractive quickstart type tutorial that emphasizes the differences and similarities to other programming languages.There is a version for Python programmers and another for Java programmers.Version 2018.06.015A.J. Hildebrand

2MATHEMATICA BASICS2MATHEMATICA BOOTCAMPMathematica Basics2.1Top things to know about the Mathematica Syntax1. All built-in mathematical constants and functions begin with a capital letter. For example, sin must be typed as Sin, not sin; the functions for sums, products,and integrations are all capitalized: Sum, Product, Integrate The same applies formathematical constants: E is the Euler constant, I is the imaginary unit, and Pidenotes the number π.2. For your own variables and functions always use lower case names. Thisis to avoid conflicts with built-in functions and constants. For example, n, n1, nmax,nmin, average, are all acceptable variables or function names, but N, Average shouldbe avoided.3. Mathematica uses square brackets, not round parentheses, for functionarguments. For example, sin(π) must be coded as Sin[Pi], not Sin(Pi). This isdifferent from languages like Python or R.4. Round parentheses are used for grouping: For example, (1 x)2 is coded as2(1 x) 2, and ex as E (x 2). This is different from LaTeX, which uses curly braces,{ . . } , for grouping.5. Mathematica evaluates expressions symbolically, rather than numerically,unless you explicitly tell it otherwise. If Mathematica cannot evaluate the expression symbolically, it will reproduce the input. For example, while Sin[Pi/2] givesthe expected answer, 1, Log[Pi/2] just reproduces the input. To get a numericalvalue, use the N function: N[Log[Pi/2]].2.2Exercises1. Basic arithmetic. Use Mathematica to evaluate the following expressions, exactly or numerically as indicated.(Hint: You’ll need the following built-in functions/constants: Pi, E, I, Log, Sin, Sqrt, N.)(a)355113(numerical)(b) sin(π/6) (exact and numerical)(c) eiπ/6 (exact and numerical)(d) e (numerical)6(e) (1 1/106 )10 (exact and numerical)(f) 21000 (exact)(g) log2 1024 (exact)(h) log 10 (numerical—here log denotes the natural log) (i) 12 (1 5) (exact and numerical)2. Sums and products. Use Mathematica to evaluate the following sums and products: Use exactevaluation unless otherwise indicated.(Hint: You’ll need the functions Sum, Product, and the built-in “constant” Infinity. The basic syntax isSum[i 2,{i,1,5}].)(a)P10(b)Pn1k 1 k (exact kk 1 2Version 2018.06.01and numerical evaluation)6A.J. Hildebrand

2MATHEMATICA BASICSP (d)kk 0 xP xkk 0 k!(e)Qn(c)MATHEMATICA BOOTCAMP k 0k1 x2 TIP: The functions Sum, Product, all have the same basic syntax, as do the functionsIntegrate, NIntegrate, Plot, Table below. In all of these cases, the first argument specifiesthe summand (or function to integrate or plot, or value in a table), and the second argumentspecifies a range using a curly brace expression such as {k,1,5} (meaning that k ranges from1 to 5). Make sure to practice this syntax and get comfortable with it.3. Integrals. Use Mathematica to evaluate the following integrals: (Hint: The relevant functions are Integrate(for symbolic/exact integration) and NIntegrate (for numerical integration). Both functions follow the syntaxof Sum and Product.)(a)R5log x dx (exact and numerical evaluation)1R x2(b) edx (exact and numerical evaluation)R 5 x2(c) 0 edx (numerical evaluation)R(d) log x dx (indefinite integral)4. Plots. Plot the following functions, using the Plot function. The syntax is the same as that of Integrate.(a) log x from x 1 to x 5.(b) sin x from x 0 to x 2π.2(c) x3 e x from x 5 to x 5.5. Tables (lists) of values. The standard way to construct lists is via Table command, which has the samesyntax as Sum, Product, Integrate, Plot.TIP: Do not use loops (For, While, etc.) in Mathematica. In contrast to other programminglanguages, there are almost always built-in functions that achieve the same result as a loop,but are much more efficient, and easier and quicker to code.(a) The first 10 squares (i.e., 1, 4, 9, . . . , 100).(b) The first 10 powers of 2, starting with 20 .(c) The numerical values of the first 10 partial sums of the seriesP k 11/k 2 .(d) A list of plots of the function sin(2kx), over the range 0 x π, for k 1, 2, 3, 4.6. Defining functions. A function definition is of the form f[n ]: ., with an underscored variable, n , onthe left side of the definition (but not on the right!) and a colon/equal sign (: ) between the left and theright side. Multivariable functions can be defined analogously.Examples: f[x ]: x 2 1, f1[x ]: Integrate[Log[t],{t,1,x}], squaresSum[x ,y ]: x 2 y 2.Recall that names for your own functions should be in lower case.In each of the following exercises, define the given function, and test your definition by evaluating the functionat a few arguments.P (a) A function, partialsum[n ], that computes the n-th partial of the series k 1 1/k 2 numerically.(b) A function, piapprox[n ], which gives π to n digits.(c) A function, sinPlot[a ], which plots the function sin(ax) over the interval 0 x 1.p(d) A function, norm[x ,y ], that outputs x2 y 2 , the norm of the vector (x, y).Version 2018.06.017A.J. Hildebrand

2MATHEMATICA BASICSMATHEMATICA BOOTCAMPProject: Approximating e by 1 1 nnWe know from calculus that (1 1/n)n converges to e. Let n e (1 1/n)n be the errorin this approximation. Then n goes to zero as n .The goal of this project is to confirm this behavior experimentally, and to (experimentally)determine the rate at which n approaches 0.1. Define functions. First let’s define functions, approx[n ], and approxerror[n ],to denote our approximation (1 1/n)n , and the approximation error n .Hints: Since we are interested in numerical (instead of exact) computations, use theN[.] function in these definitions.Test your definitions by evaluating it at a few n-values.2. Generate tables of values. Next, use the Table function to generate lists of values n to see if we can spot a pattern.Do this first for a small range of n (e.g., from 1 to 50, with step size 1), then try alarger range with a correspondingly larger step size (e.g., n 1000 to n 50000 withsteps of 1000).3. Plots the values. For further insight plot the list of values obtained by wrapping thelist inside ListPlot or ListLinePlot. To make the code more readable, give the listsappropriate names (e.g., list50 for the first 50 values, or list1000 for the first 1000values), so that you can do ListLinePlot[list50], etc.4. Experiment and make conjecture. Examining the data leads one to suspect thatthe error, n , decreases at a rate proportional to 1/n. To study this further, it isnatural to consider the product n n . Using the Table command, generate tables ofvalues of this product and convince yourself that it indeed seems to converge to acertain constant, with a numerical value of roughly 1.3. This means that n behaveslike c/n, as n , were c is this constant.5. Finding the constant. As a final challenge, try to find/guess this constant. Thereare two great tools for this: The first is WolframAlpha, www.wolframalpha.com. Asecond, and much more powerful, tool is the “Inverse Symbolic Calculator” at https://isc.carma.newcastle.edu.au/standard (Google), one of the most amazing onlineresources in mathematics! To use these tools, you’ll need to know the constant tosufficient accuracy (try to get at least 5 digits), so do the above calculation with largeenough n-values. (Taking n 105 should be no problem on any computer; n 106might still work, depending on the machine.)6. Make further conjectures. To carry this experiment further, one can examine thedifference between n and c/n. A similar analysis as above shows very convincinglythat this difference is very close to d/n2 , for a certain constantd, suggesting that one has the more precise approximation n nc nd2 O n13 , where d and d is anotherconstant.Remark: The point of this exercise is the discovery of an asymptotic relation throughnumerical experimentation. Later we’ll learn how to use Mathematica’s symbolic capabilitiesto quickly obtain expansions of the above type.Version 2018.06.018A.J. Hildebrand

2MATHEMATICA BASICSMATHEMATICA BOOTCAMPReminders: Definition of FunctionsTop things to know about definitions of variables and functions1. Always use lower case names for your own variables and functions. A capital letter inside the name is okay; for example, plotHarmonic would be fine, butPlotHarmonic should be avoided.2. Pay attention to the colors in the displayed command; if something looksout of the ordinary, there is probably a syntax error.3. Press Shift-Enter after each definition to activate it. Notice the change in colorof the function name; this indicates that the function is now available for use.4. After making a definition, test it out by evaluating it at a few samplearguments.5. Break up complex commands by defining functions for intermediate steps.This makes the code easier to read and work with, and it makes it easier to locateerrors. For example, to plot a list of values (e.g., partial sums of the harmonic series),define first a function, say values[n ], whose output is the list of the first n partialsums, then define a function, say plot[n ], that takes this list as input and outputs aplot. Test each of these functions immediately by evaluating them at a few n-values.6. Use Clear[.] to “clear out” old definitions. If you have previously defined afunction by the same name, defining it again may cause conflicts and hard-to-diagnoseerrors. To avoid this, clear out your old definitions as follows: Clear[plotHarmonic],followed by the new definition, plotHarmonic[n ]: .Conflicts among existing definitions can arise even if the old definition has been deletedfrom the notebook, and also if the definitions are in separate notebooks.Resources Elementary introduction to the Wolfram language. Free interactive online tutorial at www.wolfram.com. (Just google the title.) Very basic, Comes with lots of exercises, all with solutions. Highly recommended for beginners as a complement to these workshops. Focus on the first 6 sections(covering elementary arithmetic, functions, lists). Fast Introduction for Programmers: Short interactive tutorial, available at www.wolfram.com. (Justtype the title, ”Fast Introduction”, into the search box.) There is a version for Python programmers andanother for Java programmer, but you don’t have know either of these languages to get something out of thetutorial. Focus in particular on the sections “Lists”, “Iterators”, “Assignments”, and “Function Definitions”.Version 2018.06.019A.J. Hildebrand

3LISTS, RANDOM FUNCTIONS, AND RANDOM WALKS3MATHEMATICA BOOTCAMPLists, Random Functions, and Random WalksA “list” is the most important, and most useful, data structure in Mathematica. Make sureto master this concept, and learn how to use lists effectively in your own work.About this workshopIn this workshop, you will learn how to: Generate lists using the Table command. Perform arithmetic operations on lists (“list magic”). Use list commands such as Length (number of elements), Total (sum of elements)), Max, Min, Sort, Accumulate(list of partial sums), Extract elements from lists using the double bracket notation [[.]], and First, Last. Generate random numbers and lists of random numbers of various kind, using built-in random functions suchas RandomReal, RandomInteger, and RandomChoice. Create and visualize random walks using these random functions along with Accumulate, ListPlot, ListLinePlot,and Manipulate.Top things to know about lists in Mathematica1. A list is mathematically an ordered tuple; it is not a set. A “list” in Mathematica is like an array in other languages, or an ordered tuple in mathematics. Theorder of the elements matters, and repeated elements are allowed.2. A list is denoted by curly braces, not round parentheses. For example: {1,3,1,2,5}, not (1,3,1,2,5).3. Vectors, points, and matrices are all represented by lists, and thus requirecurly braces, not round parentheses. For example {2,3} represents the point (orvector) (2, 3), while {{1,2},{3,4}} (a list of lists) represents the matrix ( 13 24 ).4. The command to create a list of values is Table, not List. While there existsa command called List, this is a low-level function that has a different purpose andthat you won’t need.5. The command to get the sum of the elements of a list is Total, not Sum.3.1Generating Lists1. Explicit specification of list elements. The simplest way to specify a list is by listing its elements,enclosed in curly braces. For example, mylist1 {1,3,1,2,5} defines a list consisting of the five elements1, 3, 1, 2, 5, and assigns this list the name mylist1.2. Generating lists of consecutive inters: The Range commandRange allows one to quickly generate a list of integers, e.g., to use as a test list. Here are some examples: Range[5] (generates the list {1, 2, 3, 4, 5}) Range[2,5] (generates the list {2, 3, 4, 5})3. The Table Command. This is, by far, the most common and must useful way to generate a list. TheTable command has the form Table[generalterm,range], with two arguments; for example, Table[i 2,{i,1,10}].Version 2018.06.0110A.J. Hildebrand

3LISTS, RANDOM FUNCTIONS, AND RANDOM WALKSMATHEMATICA BOOTCAMP The first argument, generalterm, denotes the general term in the list you want to create (i 2 in theabove example). The second argument, range, denotes the range you want to iterate over to create the list ({i,1,10}in the above example).Specifying the range in Table, Sum, and similar commandsThe range in a Table is itself a list, and can be specified in several forms: {iterator,start,end}; e.g., {i,1,10} means that i ranges over the numbers1, 2, . . . , 10.Shortcut: {i,10} is equivalent to {i,1,10}. {iterator,start,end,increment}; e.g., to get the odd numbers from 1 to 11 (inclusive), use the range specification {i,1,11,2}. to get the list 0, 0.1, 0.2, . . . , 0.9, 1,specify 0.1 as increment: {x,0,1,0.1}. {iterator,{value1,value2,.}}, e.g., {i,{2,4,8,16}} means that i ranges overall values in the set {2, 4, 8, 16}. Notes:– The set of values in this specification is itself a list and must be enclosed in braces.– The values specified in the list here don’t have to be numerical; they can be prettymuch anything: functions (e.g., {f,{Cos,Sin,Tan}}), options in Mathematica(e.g., {color,{Red,Blue,Black}}, etc.3.2Generating random numbers and lists of random numbersIn contrast to other programming languages, Mathematica’s built-in random number functions RandomReal, RandomInteger,RandomChoice can generate lists of random numbers without needing loops. In fact, this extends to lists of anydimension, e.g., lists of points (representing a point as a list of its coordinates). This capability makes doingrandom simulations, and generating random walks of all kinds, extremely easy in Mathematica,often with a one-liner. The project below illustrates this. Creating single random numbers– RandomReal[{-1,1}] (generates a random real number in the interval [ 1, 1], with uniform probability)– RandomInteger[{1,6}] (generates a random integer in {1, 2, . . . , 6}, i.e., simulates a roll of a die)– RandomChoice[{-1,1}] (generates a random number in the set { 1, 1}, i.e., picks 1 and 1 with equalprobability) (The difference to RandomReal and RandomInteger is that with the RandomChoice commandthe elements 1 and 1 listed in {-1,1} are the only choices, whereas with the other two commands,these elements represent the endpoints of a range from which the random numbers are chosen.) Creating lists of random numbers. To get a list of random numbers, just provide a second argument tothe above functions that gives the number of random numbers you want. You can even generate matrices ormulti-dimensional lists (e.g., 10 pairs of random numbers, or two lists of 10 random numbers) by specifyingthe dimensions enclosed in curly braces (e.g., {10,2} for 10 pairs, and {2,10} for 2 lists of 10). Here aresome examples:– RandomInteger[{1,6},10] (generates a list of 10 random integers from {1, 2, . . . , 6}, i.e., simulates 10rolls of a die). This is equivalent, but sho

Mathematica notebook to try things out yourself and get comfortable with the basic syntax of Mathematica, and with working with notebooks. Try making small changes to the commands, and observe the output; use this opportunity to see what works, and what doesn’t, and try to learn from errors. Next, do the exercises on the handout

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-

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.

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

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

Mathematica. It does not assume any prior knowledge of advanced data analysis or statistical techniques. Familiarity with a programming language may prove to be useful, but it is not essential. For beginners in Mathematica, Chapter 2, Dissecting Data Using Mathematica, provides a short primer on the essentials of Mathematica programming.