Introduction to Mathematica

The basic arithmetic operations in Mathematica are +, -, *, /, and ^.  Let's evaluate

((3(((2))^4)-(7/2))/((3/4)(19)+16)).

(3*2^4-7/2)/(3/4*19+16)

To execute a Mathematica command, use Shift+Enter or the Enter button on the number pad.

We can use the N[] function to get a decimal answer.

N[178/121]

N[(3*2^4-7/2)/(3/4*19+16)]

All Mathematica functions must be capitalized and accompanied by square brackets.

Sin[Pi/2]

Sqrt[16]

sqrt[16]

sqrt(16)

Not capitalizing or using parentheses instead of brackets resulted in an error.  The natural log function is Log[], and log base 10 is Log10[].

Log10[1000]

Log[E^5]

Note that we have to capitalize names like Pi, E, and Infinity.

Sqrt[Pi]

N[Sqrt[Pi]]

E

N[E]

Infinity*5

Infinity-Infinity

If you're not sure how to do something, try to
1.  Go to the Palettes menu and then Basic Math Assistant.
2.  Go to Help, Documentation Center.
3.  Google it.
4.  Get help from your instructor or another student.


Mathematica can do algebra.

Simplify[(x+1)^2-(x-1)^2]

Expand[(x-4)*(x+3)*(x^2+8)]

Factor[-96-8 x-4 (x^2)-(x^3)+(x^4)]

Use := to assign a value to a variable.

x:=7

x

x^2

Factor[x^2-1]

The factor command didn't work because the number 7 is still stored in the variable x.  Let's clear the variable x.

Clear[x]

x

x^2

Factor[x^2-1]

Let's create our own function f(x)=(x^3).

f[x_]:=x^3

f[x]

f[2]

Plot[f[x],{x,-5,5}]

f'[x]

f'[2]

f''[x]

Derivative[2][f][x]

Integrate[f[x],x]

Integrate[f[x],{x,0,1}]

Another way to write (e^x)in Mathematica is using the Exp[] function.

Exp[x]

Let's calculate (∫_2^7)(e^(-(x^2)))dx.

Integrate[Exp[-x^2],{x,2,7}]

The answer involves the error function, which we haven't discussed in class (you can read about it in the documentation center).  Let's find a decimal approximation.

N[Integrate[Exp[-x^2],{x,2,7}]]

More examples:

Solve[x^2==25,x]

Plot[{x^2,25},{x,-10,10}]

Solve[E^x==x+7,x]

N[Solve[E^x==x+7,x]]

Plot[{E^x,x+7},{x,-10,5}]

Mathematica has an input style for performing calculations and a text style for writing descriptive text.  You can change this by going to Format, Style.  Make sure you're in input style while doing math and text style while typing text.  Examples:

2+2

Nothing happened because we're in text mode still.  Hit the down arrow to get to a new cell, which is automatically in input mode.

2+2

The answer is 4!

The answer is 4!  This comment looks much better in text style.

Make sure that any text such as your name, heading, problem numbers, etc. are all entered in text style.  Example:


John Smith
Math 209
Lab 1

1.

D[x^5,x]

2.

Integrate[x^5,x]