GETTING STARTED WITH MATHEMATICA

Similar documents
Getting Started With Mathematica

Getting Started With Mathematica

ü 1.1 Getting Started

Week 1: Introduction to R, part 1

Section 7.6 Graphs of the Sine and Cosine Functions

Functions and Graphs. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

Unit II Graphing Functions and Data

MATH STUDENT BOOK. 12th Grade Unit 4

MATHEMATICA LAB SKILLS ACTIVITY 2: ANALYZING DATA IN MATHEMATICA

Arithmetic expressions can be typed into Maple using the regular operators:

Calculus II - Math 1220 Mathematica Commands: From Basics To Calculus II - Version 11 c

Basics of Computational Geometry

ARRAY VARIABLES (ROW VECTORS)

Basic stuff -- assignments, arithmetic and functions

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

EGR 111 Introduction to MATLAB

MATH 162 Calculus II Computer Laboratory Topic: Introduction to Mathematica & Parametrizations

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

Lagrange Multipliers and Problem Formulation

Dr Richard Greenaway

Ph3 Mathematica Homework: Week 1

HANDS-ON START TO WOLFRAM MATHEMATICA. and Programming with the Wolfram Language. Cliff Hastings Kelvin Mischo Michael Morrison.

Mathematical Experiments with Mathematica

MEI GeoGebra Tasks for AS Pure

Use Parametric notation. Interpret the effect that T has on the graph as motion.

INDEX INTRODUCTION...1

Mastery. PRECALCULUS Student Learning Targets

Table of Laplace Transforms

Calculus III. 1 Getting started - the basics

Introduction to MATLAB

EE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext Objective. Report. Introduction to Matlab

8.4 Graphs of Sine and Cosine Functions Additional Material to Assist in Graphing Trig Functions

Algebra 2 Semester 2 Final Exam Study Outline Semester 2 Final Exam Study Tips and Information

Guide to Planning Functions and Applications, Grade 11, University/College Preparation (MCF3M)

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

1 Introduction to Matlab

A Brief Introduction to Mathematica

1 Basic Mathematical Operations

George Mason University Signals and Systems I Spring 2016

Math 1191 Mathematica Introduction

A Mathematica Tutorial

YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM

Lesson 6-5: Transforms of Graphs of Functions

Dynamics and Vibrations Mupad tutorial

John's Tutorial on Everyday Mathcad (Version 9/2/09) Mathcad is not the specialist's ultimate mathematical simulator

1 Maple Introduction. 1.1 Getting Started. 1.2 Maple Commands

Graphing Trig Functions - Sine & Cosine

[ MATLAB ] [ Resources ] PART TWO: SIMULINK

FIFTH GRADE Mathematics Curriculum Map Unit 1

Getting Started with Mathematica

Appendix H: Introduction to Maple

Beginner s Mathematica Tutorial

STEPHEN WOLFRAM MATHEMATICADO. Fourth Edition WOLFRAM MEDIA CAMBRIDGE UNIVERSITY PRESS

PRECALCULUS MATH Trigonometry 9-12

Scientific Computing: Lecture 1

MATLAB = MATrix LABoratory. Interactive system. Basic data element is an array that does not require dimensioning.

AP Calculus AB. Table of Contents. Slide 1 / 180. Slide 2 / 180. Slide 3 / 180. Review Unit

Dear Accelerated Pre-Calculus Student:

7 Fractions. Number Sense and Numeration Measurement Geometry and Spatial Sense Patterning and Algebra Data Management and Probability

1. The Pythagorean Theorem

PHYS 5061 Lab 1: Introduction to LabVIEW

INTRODUCTION TO MATHEMATICA FOR PHYSICS 103

We can conclude that if f is differentiable in an interval containing a, then. f(x) L(x) = f(a) + f (a)(x a).

To see what directory your work is stored in, and the directory in which Matlab will look for files, type

An Introduction to Maple This lab is adapted from a lab created by Bob Milnikel.

Teacher Activity: page 1/9 Mathematical Expressions in Microsoft Word

MEI Desmos Tasks for AS Pure

Class #15: Experiment Introduction to Matlab

Parametric Representation throughout Pre-Calculus Richard Parr Rice University School Mathematics Project

COMP 110 Project 1 Programming Project Warm-Up Exercise

Summer Review for Students Entering Pre-Calculus with Trigonometry. TI-84 Plus Graphing Calculator is required for this course.

Functions and Transformations

2. Periodic functions have a repeating pattern called a cycle. Some examples from real-life that have repeating patterns might include:

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Common Core State Standards - Standards for Mathematical Practice

Introduction to Matlab Simulink. Control Systems

Integrated Mathematics I Performance Level Descriptors

6.001 Notes: Section 6.1

Maple Quick Start. Maplesoft, a division of Waterloo Maple Inc.

HW #7 Solution Due Thursday, November 14, 2002

Dynamical Systems - Math 3280 Mathematica: From Algebra to Dynamical Systems c

Lab#1: INTRODUCTION TO DERIVE

GCSE-AS Mathematics Bridging Course. Chellaston School. Dr P. Leary (KS5 Coordinator) Monday Objectives. The Equation of a Line.

Unit 4 Graphs of Trigonometric Functions - Classwork

Summer Review for Students Entering Pre-Calculus with Trigonometry. TI-84 Plus Graphing Calculator is required for this course.

Quadratic Functions CHAPTER. 1.1 Lots and Projectiles Introduction to Quadratic Functions p. 31

CSCE 120: Learning To Code

y= sin( x) y= cos( x)

Algebra 2 Common Core Summer Skills Packet

Introduction to MATLAB

1-- Pre-Lab The Pre-Lab this first week is short and straightforward. Make sure that you read through the information below prior to coming to lab.

2D ANIMATION & INTERACTION COURSE WEEK 5 QUICK REFERENCE

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Chapter 5. Radicals. Lesson 1: More Exponent Practice. Lesson 2: Square Root Functions. Lesson 3: Solving Radical Equations

Investigation and Justification (Proof) Thread

open a text line to annotate your work is Alt-7. From Eq. 2.5 we use the "sum" function in Mathematica to consider the (finite) sum

Precalculus: Graphs of Tangent, Cotangent, Secant, and Cosecant Practice Problems. Questions

Mathematics 96 (3581) CA (Class Addendum) 2: Associativity Mt. San Jacinto College Menifee Valley Campus Spring 2013

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Transcription:

GETTING STARTED WITH MATHEMATICA Loading Mathematica : If you are on any Loyola network computer, you should be able to load Mathematica by clicking on the start button (on the lower left of the computer screen), and searching for Mathematica. It might take a minute or two for Mathematica to load. You can also download a student copy of Mathematica onto your personal computer or laptop by following the directions posted on the link you can find on the course webpage. Basic Calculations and Capabilities: Mathematica has become one of the standard software platforms used by scientists in many disciplines. While we will only scratch the surface of what Mathematica can do, it is my goal that this semester will provide you with the foundation to expand upon your knowledge of Mathematica and use it not only for coursework, but in diverse research applications. Unlike many other software packages I have used, Mathematica has a very good online documentation center (click on the help tab at the top of each notebook). Let' s demonstrate a few of Mathematica' s abilities. First, it acts as a calculator. If we want the value of the cos of 30 degrees we type : In[1]:= Cos[π / 6] Out[1]= 2 3 Notice that radians are the default measure for trig functions; the following command allows us to use degrees: In[2]:= Out[2]= Cos[30 Degree] 2 3 Once we input the command, we obtain output by simultaneously hitting the Shift and keys; if you have an extended keyboard, you can just hit the key on the extended keyboard. When you take thermodynamics, you will learn how to calculate probabilities; for instance, the probability of obtaining exactly 50 heads in 100 tosses of a fair coin is: In[3]:= (100! / (50! 50!)) (0.5)^100 Out[3]= 0.0795892

2 gettingstarted.nb Telling us that the probabiility of getting 50 heads is just under 8 % (why is this, the maximum probability, so low)? If you wanted to plot the total probability distribution, the following code will work : In[60]:= Clear[prob, n, ntotal, p, q] prob[ntotal_,n_,p_,q_]:=ntotal!/((n!)(ntotal-n)!)p^n q^(ntotal-n) ListPlot[Table[prob[100,n,0.5,0.5],{n,0,100}],PlotRange All] 0.08 0.06 Out[62]= 0.04 0.02 20 40 60 80 100 And we produce a plot of the probability of flipping n heads out of 100 tosses. These three lines of code saved a lot of grinding and finding with a calculator. Graphing : Mathematica will allow you to produce a wide array of plots and graphs; these will be very helpful to us throughout the semester. First, a simple example, the graph of sin x from - π to π : In[10]:= Plot[Sin[x], {x, -π, π}] 1.0 0.5 Out[10]= -3-2 -1 1 2 3-0.5-1.0 Now, plots of sin x, sin 2 x and sin 3 x on the same set of axes :

gettingstarted.nb 3 In[11]:= Plot[{Sin[x], Sin[2 x], Sin[3 x]}, {x, -π, π}] 1.0 0.5 Out[11]= -3-2 -1 1 2 3-0.5-1.0 If you study these examples, you will notice some patterns emerging. First, notice that all library functions in Mathematica (functions that already exist in Mathematica) start with capital letters. Then, notice that the argument of the function is always in square brackets. Braces, also knows as curly brackets ( { } ) are used for elements of a list (such as the list of functions to be plotted, or the list of parameters controlling the plot). Mathematica can produce 3D plots: In[13]:= Plot3D[x^2 + 2 x y + y^2, {x, -3, 3}, {y, -3, 3}] Out[13]= And plot vector fields:

4 gettingstarted.nb In[14]:= VectorPlot[{y, -x}, {x, -3, 3}, {y, -3, 3}] 3 2 1 Out[14]= 0-1 -2-3 -3-2 -1 0 1 2 3 We saw above that ListPlot takes discrete points from a table and produces a graph. Here is a graph of the first 25 values of n 2 : In[15]:= ListPlot Table n 2, {n, 1, 25} 600 500 400 Out[15]= 300 200 100 5 10 15 20 25 And to make this a continuous curve :

gettingstarted.nb 5 In[16]:= ListLinePlot[Table[n^2, {n, 1, 25}]] 600 500 400 Out[16]= 300 200 100 5 10 15 20 25 You can animate a graph using the Manipulate command. Before you type the code into your notebook, see if you can figure out what should happen. Now, type in the code and execute by hitting shift- : Clear[x, y, amp, k, ω, t] y[amp_,k_,x_,ω_,t_]:= amp Sin[k x - ω t] Manipulate[Plot[y[2,2,x,5,t],{x,0,10}],{t,0,5}] t 1.39347 2 Out[19]= 1 2 4 6 8 10-1 -2 In a few weeks, we will study Fourier series in which we will learn how to express almost any periodic function as a series of sin waves. Let' s see how a series of sin waves can produce a the square wave below :

6 gettingstarted.nb In[20]:= Clear[f,x,n] Manipulate[Plot[(4/π)Sum[Sin[n x]/n,{n,1,a,2}],{x,-2π,6π}],{a,1,31}] a 31. 1.0 Out[21]= 0.5-5 5 10 15-0.5-1.0 The free variable a represents the number of terms in the summation. If a = 1, we have just one sin wave and we obtain, of course, a pure sinusoidal wave. However, as we add additional sin waves, we can see that the sum converges to a square wave. Fourier series are a powerful way to analyze periodic phenomena. Solving Equations : There are many routines in Mathematica that will allow you to solve all manner of problems. A simple quadratic can be solved via: In[22]:= Solve[3 x^2-2 x + 6 0, x] Out[22]= x 1 3 1 - i 17, x 1 1 + i 17 3 And the output shows the two complex roots of this equation. We do not even need to use numbers; suppose we want to solve for the acceleration of the masses in an Atwood' s machine. We write Newton' s second law for the two masses (m and M) : In[23]:= Out[23]= Solve[{T - m g m a, T - M g - M a}, {a, T}] a - g m - g M m + M, T 2 g m M m + M where T is the tension; the output yields analytic expressions for the acceleration of the system and the tension in the rope.

gettingstarted.nb 7 Differential equations can be analyzed via: In[24]:= DSolve[y''[x] - 5 y'[x] + 6 y[x] 0, y[x], x] Out[24]= y[x] e 2 x C[1] + e 3 x C[2] And you get the expected results for the equation y - 5y +6y = 0 And both definitie and indefinite integrals can be evaluated: In[25]:= Integrate[Tan[x], x] Out[25]= -Log[Cos[x]] In[27]:= Out[27]= Integrate 1 1 + x 2 ^3, {x, 0, } 3 π 16 Quirks and Cautions: As with any software package, especially one this comprehensive, one can easily feel overwhelmed with all of the possible applications, utilities and opportunities for adding elegance and nuance to your work. I will do my best not to throw too much into any one classnote, and will allow you time to learn the software by using it--a few digestible bites at a time. Mathematica has a very good documentation center online (under the help tab), so I urge you to explore Mathematica as much as you can. I want to mention a few points that you should keep in mind as you begin working with this program. Using Functions in Mathematica: Mathematica has hundreds if not thousands of library functions. We will use several of them, and the basic ones (like Sin, Cos, Log, Integrate, Plot and others) will become familiar to you..when you call a library function, you have to type it exactly as Mathematica expects. In particular, all Mathematica library functions becomes with a capital letter. Compare the output we get from these two statements: In[28]:= Cos[π / 6] Out[28]= 3 2 In[29]:= cos[π / 6] Out[29]= cos π 6

8 gettingstarted.nb In the first case, we obtain the value of cos 30 o. In the second case, Mathematica does not recognize this as the library function for the cosine of an angle, since the statement did not start with a capital letter. Delimiters : Brackets, Braces and Parentheses In Mathematica, brackets, braces and parentheses all have very specific meanings.we have seen that you must use brackets whenever you call a library function. Braces (curly brackets) are used when you are denoting lists; you encountered this when we plotted three sine functions on the same graph.in that case, we created a list of the three functions we wished to plot. We also used braces in solving two equations simultaneously (notice there were no braces when we solved just one equation); we use braces in setting up the range over which to plot a function : {x, -π, π} is the Mathematica command meaning "plot over x from -π to +π".similarly, the braces used in the definite integral {x, -π, π} mean "integrate over x, from -π to +π". Parentheses are used for grouping as they are in normal mathematical writing; however, in Mathematica, only parentheses are recognized as a means of grouping terms to clarify the order of operation You can read more details about these in the online documentation by typing in "The Four Kinds of Bracketing." Coefficients and Multiplication Let' s say you want to do a simple calculation and multiply 30 times 50. You can do this simply by typing in one number, leaving a space and then typing the next number : In[30]:= 30 50 Out[30]= 1500 The "x" that appears was entered automatically by the program when I left a space; the output of 1500 was generated when I hit "Shift Enter" In this version of Mathematica, the program will automatically put a space between a number and a variable.try to reproduce these steps when you are trying out the program.first, I will set x = 4, and then evaluate 2 x :

gettingstarted.nb 9 In[35]:= x = 4 2 x Out[35]= 4 Out[36]= 8 Notice that we obtained two output lines; the first output line corresponds to the first input line and tells us that we set x = 4. The second output line tells us that when I multiply x times 2, I get 8. (Yes, I know, horribly profound).if I only want the final output, I can suppress the first output by using a semicolon: In[37]:= x = 5; 2 x Out[38]= 10 If you are inputting an equation using only symbols, say F = m a, you will need to leave a space between the two variables (the m, the a). Without this space, Mathematica will interpret ma as the new variable ma. See the two examples below; the first one with proper syntax: In[57]:= m = 2; a = 5; f = m a; Print["The force is ",f] The force is 10 Without proper syntax: In[44]:= m = 2; a = 5; f = ma; Print["The force is ",f] The force is ma Equal Signs in Mathematica: Mathematica has 3 different types of equal signs; it is important that we learn how to use each one in its proper context. Immediate Assignment In traditional mathematics, we use the "=" sign for many different purposes.we make use of this

10 gettingstarted.nb symbol when we want to assign a value to a variable (x = 3). We also use this sign when we establish a function (f (x) = 2 x + 2 and also when we want to solve equations (3 x + 2 y = 0).While we use the same symbol for all of them, there is actually different logic involved in each operation. To account for the different logical meanings of equal, there are different types of equal signs in Mathematica. You have already encountered two of them in this write up.the "=" you are familiar with (and the one used immediately above) is used when you want to make an immediate assignment of a value to a variable.in the examples above, each time we set x equal to a number that number was assigned to x immediately, and will remain assigned as the value of x until we either reassign x or Clear[x]. So what would happen if I just input x and hit shift- : In[47]:= x Out[47]= 5 Recall that I set x = 5 above. Since I had not cleared the value of x or assigned a new value to this variable, Mathematica will retain the assignment x = 5 until I clear or change it. If I now input the quadratic: In[48]:= x 2-10 x + 7 Out[48]= - 18 Which is the value of this expression when x = 5. This is why it is always a good idea to Clear all variables before you execute any program. Solving Equations and the Double Equal Sign As we saw above, Mathematica is a very useful tool for solving various sorts of equations.when we solve equations, we make use of a double equal sign "= =". As shown in previous examples, we can solve single equations, systems of equations, and even solve equations symbolically. Let s solve the general quadratic equation: In[49]:= Solve[a x^2 + b x + c 0,x] Solve::ivar : 5 is not a valid variable. Out[49]= Solve[125 + 5 b + c 0, 5] Well, now you know what Mathematica error statements look like. Why did we get this error? Remember we set x = 5; until we clear this value, Mathematica will equate x and 5 in all contexts.

gettingstarted.nb 11 Since we want to solve for x, Mathematica correctly tells us that 5 (which is still equivalent to x in Mathematica world) is not a variable. We correct this simply: In[52]:= Clear[a,b,c,x] Solve[a x^2 + b x + c 0,x] Out[53]= x -b - b2-4 a c 2 a, x -b + b2-4 a c 2 a And we get the two roots of the quadratic equation. Note that "Clear[x]" starts with a capital "C", and the argument of the function is in brackets. Creating functions and the colon-equal sign: Suppose we want to create a function in Mathematica, say something as simple as f(x) = x 2. We proceed as: In[54]:= Clear[f,x] f[x_]:= x 2 f[4.5] Out[56]= 20.25 Note the two pieces of syntax here; we use an underscore after the x in the declaration of the function, and we use the := sign to indicate that x 2 will be substituted for x. Earlier, we saw how to create a multivariate function, when we defined the probability of a coin toss in terms of the total number of flips, the number of successes (n), and the probabilities of success (p) and failure (q). This is just the barest of introductions to Mathematica. By the end of the semester, it is my goal that you will gain fluency in this very powerful programming language.