Fundamental Commands

To define a constant, use a single equals sign:

a = 5

5

You can include text by using Command 7

Once defined, you can use the constant anywhere you want:

a + 13

a^3

18

125

To avoid problems,  erase from memory  the assigned value to a

Clear[a]

When defining a function, you need to remember two important things:
    Use an underscore character after each argument name on the left-hand side (but not on the right-hand side)
    Use a := in the middle

f[x_] := x^2 + 13

To check your definition use the question mark before the name of a function
Once defined, you can use the function

?f

Global`f

f[x_] := x^2 + 13

f[5]

f[a]

38

13 + a^2

f[100 !]

f[b + c]

13 + (b + c)^2

You need to be carefull with User define functions.
For example we want to change the function

f[x_]:= x^2
?f

Global`f

f[x_] := x^2

Notice that the function was subtituted by the new definition. But now you change your mind and redefine the function

f[y_Integer] := y^3

?f

Global`f

f[y_Integer] := y^3
f[x_] := x^2

Notice the two different definitions saved by MATHEMATICA.  One for real numbers and one for integers

{f[2],f[2.]}

{8, 4.}

Again, you change the definition of "f"

f[x_] := Sqrt[x]

?f

Global`f

f[y_Integer] := y^3
f[x_] := x^(1/2)

f[4]

64

In order to avoid problems use Clear

Clear[f]
f[x_] := Sqrt[x]

?f

Global`f

f[x_] := x^(1/2)

The square root of 10

f[10]

Sqrt[10]

10^(1/2)

10^(1/2)

We need to tell MATHEMATICA that we need a numerical value.  We can use a decimal point

10.^(1/2)

3.16228

or we can use the N function and ask for 50 digits:

N[ Sqrt[10], 50 ]

3.1622776601683793319988935444327185337195551393252

3^100

515377520732011331036461129765621272702107522001

N[%]

The command % refers to the previous output

5.15378*10^47

In the following expression I stand for (-1)^(1/2)

(3 + 4 I) ^10

-9653287 + 1476984 


Created by Mathematica  (September 7, 2006) Valid XHTML 1.1!