1. Getting Started

Legal Notice, Disclaimer, and Book Ordering Information:

Null

Setup

\(Clear["Global`*`"]; 
Off[General::spell]; 
Off[General::spell1]; 
    \)

1.2 Arithmetic and Algebra

1.2.1  Arithemetic and Notation

Function Form

N[Pi]

N[Pi, 20]

Postfix Form

Pi  //  N

Use # and & to make pure function

Pi  //  N[#, 50] &

Successive operations

E^(I x)  //  Series[#, {x, 0, 5}]&  //  Normal

1.2.2  Algebra

Clear["Global`*`"];

eq0  =  (1 + x^2)^5

eq1  =  Expand[eq0]

Or we can use the postfix form of the same command:

eq1  =  eq0 // Expand

eq1  //  Simplify

Note, however, that many commands do NOT work on equations:

eq0  =  {(1 + x^2)^5  ==  0}

eq1  =  Expand[eq0]

Must use a work-around to change the form of  equations:

eq0[[1]]

eq0[[1, 1]]

eq0[[1, 1]] // Expand

eq1  = 
       {(eq0[[1, 1]] // Expand)  ==  
          (eq0[[1, 2]] // Expand)}

Can use the GaussianIntegers option of Factor to obtain complex factors.

Factor[eq1[[1, 1]]]

Factor[eq1[[1, 1]], GaussianIntegers  ->  True]

Options[Factor]

Note difference (Extension->None) from output shown in book.
This is a difference between Mathematica v.2.x and Mathematica v.3.0.1.

1.2.3  Mapping Expressions

Clear["Global`*`"];

eq0  =  a1 (b + c/2)^2  +  a2 (d + e/3)^3

eq1  =  eq0 // Expand

Note:  This is the same output as in book, obtained without the //Simplify command.

eq1  //  Simplify

Note:  After the //Simplify command, the output goes bact to essentially the input form.
This is a difference between Mathematica v.2.x and Mathematica v.3.0.1.

eq2  =  eq1  //  Collect[#, {a1, a2}]&

eq3  =  eq2  //  Map[Factor, #, {2}]&

Note:  This is the same output as produced with the //Simplify command.
This is a difference between Mathematica v.2.x and Mathematica v.3.0.1.

eq3  =  eq2  //  Map[factor, #, {2}]&

1.2.4  Rules

Clear["Global`*`"];

Substitution operation /. (single substitution)

(x + z)^2  /.  z ->  Sin[k y]

(x + z)^2  /.  {z ->  Sin[k y],  k  ->  1}

Replacement  operation //. (multiple substitutions)

(x + z)^2  //.  {z ->  Sin[k y],  k  ->  1}

1.2.5  Conjugation

Clear["Global`*`"];

a  +  2 I b  /.  I  ->  -I

Note: Doesn't work!

a  +  2 I b  //  FullForm

Note: This is what Mathematica is really doing.  Construct rule accordingly.

conjugateRule  =  {Complex[re_, im_]  ->  Complex[re, -im]};

a  +  2 I b  /.  conjugateRule

1.2.6  User-Defined Complex Conjugate Rule

Clear["Global`*`"];

\(conjugate::usage\  = 
	
      "A simple method of computing the conjugate of an object which is explicitly Complex"; 


    conjugateRule\  = \ {Complex[re_, im_] :> Complex[re, \(-im\)]}; 

    conjugate[exp__]\  := \ exp\  /. \ conjugateRule; \)

I Exp[ I k x]  // Conjugate

Note: Conjugate is not sure if kx is real or complex, and so it leaves Conjugate[k x] in the exponent.  The user rule treats kx as real.

I Exp[ I k x]  // conjugate

1.2.7  Algebraic Equations

Equation solution

Clear["Global`*`"];

\(eq1\  = \ a\ x^2\  + \ b\ x\  + \ c\  == \ 0; 

    sol1\  = \ Solve[eq1, x]\)

x  /.  sol1[[1]]

x  /.  sol1[[2]]

eq1  /.  sol1

eq1  /.  sol1  //  Simplify

Coupled Equations

Clear["Global`*`"];

eq2  =  {a x + b y == c,  a x - b y == d};

Use Reduce instead of Solve

eq3  =  Reduce[eq2, {x, y}]

Extract desired solution by specifying [[solution,{items}]]

eq3[[3, {2, 3}]]

1.2.8  Threading Expressions

Clear["Global`*`"];

Use Thread to relate components of two separate lists

\(vector1 = {x1, y1}; 
vector2 = {x2, y2}; 

    Thread[vector1 == vector2]\)

Thread[vector1 == 0]

Needs["Calculus`VectorAnalysis`"]

Thread[{x, y, z}  ->  
        CoordinatesToCartesian[{r, theta, phi}, Spherical] ]

eq1  =  x + 1/a  ==  y/a;

a eq1

Thread[a eq1, Equal]  //  ExpandAll