Getting Started With Mathematica

Similar documents
Getting Started With Mathematica

GETTING STARTED WITH MATHEMATICA

APPM 2460 Matlab Basics

1 Introduction to Matlab

Basic stuff -- assignments, arithmetic and functions

Graphing Trig Functions - Sine & Cosine

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

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

Unit II Graphing Functions and Data

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

Basics of Computational Geometry

Lesson 6-5: Transforms of Graphs of Functions

Section 0.3 The Order of Operations

Week 1: Introduction to R, part 1

Math 25 and Maple 3 + 4;

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

Note that ALL of these points are Intercepts(along an axis), something you should see often in later work.

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6

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

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

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

APPM 2460 PLOTTING IN MATLAB

2.9 Linear Approximations and Differentials

The Justin Guide to Matlab for MATH 241 Part 1.

Algebra 2 Common Core Summer Skills Packet

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

Ph3 Mathematica Homework: Week 1

INDEX INTRODUCTION...1

Dr Richard Greenaway

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

UPCAT Reviewer Booklet

Lab 1 Intro to MATLAB and FreeMat

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

hp calculators HP 35s Using Algebraic Mode Calculation modes Functions of a single number in algebraic A simple example in algebraic

Section Graphs of the Sine and Cosine Functions

C Pointers 2013 Author Riko H i

1 Basic Mathematical Operations

x y

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

Chapter 7: Analytic Trigonometry

A Mathematica Tutorial

MATH STUDENT BOOK. 12th Grade Unit 4

6.001 Notes: Section 4.1

Parametric Surfaces and Surface Area

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays

Lesson 6: Manipulating Equations

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

(Refer Slide Time: 02:59)

Structures of Expressions

Table of Laplace Transforms

Introduction to Matlab

AP Calculus BC Summer Assignment

EGR 111 Introduction to MATLAB

Calculus III. 1 Getting started - the basics

Lagrange Multipliers and Problem Formulation

ACT Math test Trigonometry Review

Using the Equation Palette

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6. ) is graphed below:

Math 2250 Lab #3: Landing on Target

Introduction to Matlab

INTRODUCTION TO MATHEMATICA FOR PHYSICS 103

Working with Algebraic Expressions

Math 7 Elementary Linear Algebra PLOTS and ROTATIONS

Section 7.6 Graphs of the Sine and Cosine Functions

MATLAB Guide to Fibonacci Numbers

Beginner s Mathematica Tutorial

Introduction to MATLAB

MEI GeoGebra Tasks for AS Pure

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Math 3 Coordinate Geometry Part 2 Graphing Solutions

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

You can take the arccos of both sides to get θ by itself.

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

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

ARRAY VARIABLES (ROW VECTORS)

ü 1.1 Getting Started

Class #15: Experiment Introduction to Matlab

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

(Refer Slide Time: 1:27)

ELEMENTARY MATLAB PROGRAMMING

6 Stephanie Well. It s six, because there s six towers.

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

Introduction to Matlab

MEI Desmos Tasks for AS Pure

Intro Right Triangle Trig

Homework 1 Description CmpE 362 Spring Instructor : Fatih Alagoz Teaching Assistant : Yekta Said Can Due: 3 March, 23:59, sharp

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

Quiz 6 Practice Problems

6.001 Notes: Section 6.1

Unit 2: Function Transformation Chapter 1. Basic Transformations Reflections Inverses

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

MTH 122 Calculus II Essex County College Division of Mathematics and Physics 1 Lecture Notes #11 Sakai Web Project Material

Why Use Graphs? Test Grade. Time Sleeping (Hrs) Time Sleeping (Hrs) Test Grade

L A TEX Primer. Randall R. Holmes. August 17, 2018

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

MPM2D. Key Questions & Concepts. Grade 10Math. peace. love. pi.

Section 1.5 Transformation of Functions

Project 2: How Parentheses and the Order of Operations Impose Structure on Expressions

A quick Matlab tutorial

Week 4: Day 1: Unit circle and meaning!

Transcription:

Getting Started With Mathematica First Steps This semester we will make use of the software package Mathematica; this package is available on all Loyola networked computers. You can access Mathematica by going to the START button in the lower left of your computer screen and: Single Click on Start Select ALL PROGRAMS Select LOYOLA SOFTWARE Select MATH AND COMPUTER SCIENCE Select MATHEMATICA 6 It may take a little while for Mathematica to load. Basic Calculations and Capabilities I want you to become familiar with Mathematica during this semester for a number of reasons. First, it is one of the most, if not the most, comprehensive and powerful software packages of its sort. Second, while you may already be familiar with MAPLE or MATLAB, it is always a good idea to know as many different languages or formats as possible The range of what Mathematica can do is quite impressive. It can serve as a simple calculator: For instance, if we wish to find the value of cos 30 degrees, we would enter the input: In[57]:= Cos@π ê 6D by simultaneously hitting "Shift-Enter" you will receive the output: Out[57]= 3 If you want to try more ambitious calculations, we can use Mathematica to determine the probability of getting exactly 50 heads in 100 tosses of a fair coin; we would input: In[58]:= H100! ê H50! 50!LL H0.5L^100 and recieve the output : Out[58]= 0.079589 Mathematica is very useful in creating plots and graphs that can help you understand the nature of a function or solution. For instance, if you want to plot the curve of y=sin(3x) between - p and p, you would input:

mgettingstarted.nb In[59]:= Plot@Sin@3 xd, 8x, π, π<d 1.0 0.5 Out[59]= -3 - -1 1 3-0.5-1.0 Suppose you wanted to investigate the behavior of several sine waves at once, you could input : In[60]:= Plot@8Sin@xD, Sin@ xd, Sin@3 xd<, 8x, π, π<d 1.0 0.5 Out[60]= -3 - -1 1 3-0.5-1.0 This software also allows us to solve equations, such as y = 3 x - x + 6 = 0: In[61]:= Solve@3 x^ x + 6 0, xd Out[61]= ::x 1 3 J1 17 N>, :x 1 J1 + 17 N>> 3 The output shows the two roots of x. We can solve equations analytically; suppose we have a simple Atwood' s machine with masses M and m, we can solve for the tension in the rope and acceleration of the system by entering the equations derived from applying Newton' s Second Law to this system : In[63]:= Out[63]= Solve@8T mg ma, T Mg Ma<, 8a, T<D gm gm gmm ::a,t m + M m + M >> here the output line shows in analytic terms the solution to this set of equations. During the course (especially when we are studying Fourier Series and Transforms), you will be asked to brush off your skills integrating trig functions. One of Mathematica' s most endearing qualities is its ability to integrate almost anything, performing both definite and indefinite integrations. For instance, if we wish to integrate tan 3 x, we would enter:

mgettingstarted.nb 3 In[70]:= Integrate@Tan@xD^3, xd Out[70]= Log@Cos@xDD + Sec@xD If you want to find the definite integral of the Gaussian function integrated over all space : In[71]:= Out[71]= Integrate@Exp@ x^d, 8x,, <D π You are strongly encouraged to use Mathematica to check the results of your work. On many homework assignments, you will be free to use the results of Mathematica rather than carrying out the integrations by hand. (On the first homework, though, I do want you to do the integrals by hand and show your work; however, feel free to use Mathematica as a check.) As we proceed through the semester, you will be able to make more and more use of this software. 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 subtelty and nuance to your work. I will do my best not to try to throw too much into any one note, and allow you time to learn the system by doing it; a few simple chunks at a time. I hope you will explore Mathematica as much as you can; there is a pretty good online documentation center that will allow you to go into as much depth on any subject as you wish. In this section, I want to mention a few points that you should keep in mind as you begin working with this program. ü Mathematica 6 The current version of the program, and the one we have loaded on Loyola computers, is Mathematica 6. This version was introduced in the summer of 007 and represents a significant change (and improvement) over past versions. One of the consequences of this is that if you get some texts to help you use Mathematica in this or other courses, you may find that some of the functions they call no longer exist, or their parameters have changed. I will point some of these out as the semester goes on, I just want to call this to your attention now. ü Functions Mathematica has hundreds, maybe thousands of functions. We will use a lot of them this term, most of which will be very familiar to you but some of which may be (and likely will be) brand new. When you call a function, you have to call it exactly as the program expects it to be called. In particular, all functions must begin with a capital letter. If you recall our first example, that of finding cos(30), we typed it as: In[64]:= Out[64]= Cos@π ê 6D 3 Mathematica requires that the first letter of all functions be capitalized. (Notice also that we input radians and not degrees). What would happen if we typed : In[66]:= cos@π ê 6D Out[66]= cosb π 6 F

4 mgettingstarted.nb It outputs exactly what we typed in; by using the lower case, Mathematica assumes that we have defined some new function and is waiting for more instructions. Some of the common function calls you might make are : In[67]:= Out[67]= In[68]:= Sin@π ê 6D 1 Exp@3.74D Out[68]= 4.098 In[69]:= Log@Exp@3DD Out[69]= 3 From the last example, you can see that "Log" refers to natural (base e) logs. ü Brackets, Braces and Parentheses In Mathematica, brackets, braces and parentheses all have very specific meanings. For instance, if you refer back to the examples where we evaluated various trig functions, and called different functions such as Integrate, Solve, Sin, Cos and so on, we had to use brackets in our function call. For instance, if we try to evaluate: In[7]:= Out[7]= Cos Hπ ê 6L Cos π 6 We do not get the evaluation that we want. Brackets are always used when calling a function. Braces 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, -p, p} is the Mathematica command meaning "plot over x from -p to +p". 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[73]:= 30 50 Out[73]= 1500

mgettingstarted.nb 5 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 x: In[76]:= x = 4 x Out[76]= 4 Out[77]= 8 If you type the "" followed by the "x", this version of Mathematica will automatically leave a space; older versions of the program did not. Also, 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, I get 8. (Yes, I know, horribly profound). If I only want the final output, I can suppress the first output by: In[88]:= x = 5; x Out[89]= 10 Here, by using a semicolon after the assignment statement I am able to suppress the output. However, if you are inputting an equation symbolically, say F=ma, you will need to leave a space between the variable "m" and the variable "a"; without the space, Mathematica will assume you are defining a variable called "ma". ü Equal Signs ü Immediate Assignment In traditional mathematics, we use the "=" sign for many different purposes. We make use of this symbol when we want to assign a value to a variable (x=3); we use this sign when we establish a function (f(x)=x+); and we use this symbol when we want to solve equations (3x+y=0). While we use the same symbol for all of them, there is different logic involved in each operation. There are three 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. 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]. For instance, if I just type in x and hit "shift enter" : In[90]:= x Out[90]= 5 The output is 5, since this is the last value x had from above. If I now evaluate : In[91]:= x^ 10 x + 7 Out[91]= 18 The output evaluates the expression with the value of 5 assigned to x.

6 mgettingstarted.nb ü 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 are solving equations, we make use of a double equal sign "==". As shown above, we can do this for one equation, multiple equations, and can even use this to solve equations symbolically. If we want to solve the general quadratic equation, we would input: In[9]:= Solve@a x^ + bx+ c 0, xd General::ivar : 5 is not a valid variable. à General::ivar : 5 is not a valid variable. à Out[9]= Solve@5 a + 5b+ c 0, 5D I did that a little bit on purpose to introduce you to what error messages look like, and to point out an important feature of good programming. Remember just above we said that the statement x = 5 assigned the value of 5 to x as long as we did not re - assign or clear x? Well, even though we wanted to do something else with x, Mathematica remembers and doesn' t understand our Solve statement, thinking "this makes no sense, 5 is not a variable" So, we clear x and proceed: In[93]:= Clear@xD Solve@a x^+ bx+ c 0, xd Out[94]= ::x b b 4ac a >, :x b + b 4ac a >> Note that "Clear[x]" starts with a capital "C", and the argument of the function is in brackets. The output gives us the roots of the quadratic equation as we know and love them. The final "x" after the comma means "solve for x". Remember, we need to leave spaces between coefficients and variables, if we input: In[95]:= Solve@ax^ + bx + c 0, xd Out[95]= 88<< The output we get in this case is Mathematica' s way of saying either there is no solution or it has no idea what we are asking. The difference here is that by leaving no spaces between the a and the x, and the b and the x, it inteprets the cluster of symbols "ax^" and "bx" to be variables in their own right, and it simply cannot proceed solving for x when the only variables it has are "ax^" and "bx" The danger in introducing a new software package is to try to show too much at once; I hope I have not done this. I am not by any means an expert with Mathematica, but have used it enough to think it is a wonderful tool for the sort of work we will do this semester and beyond. Oh, this set of notes was written in Mathematica.