Symbolic and Numeric Calculations, Roots Finding,
File Input and Output

Mathematica  has a powerful array of functions that solve equations symbolically and ways to simplify expressions.  Many people use Mathematica because it removes the tedium of doing algebra with pencil and paper---and perhaps more importantly it doesn't make errors!  However, one frustrating aspect is getting Mathematica to represent an expression in exactly the form you desire.  Sometimes it is possible with patience,practice and skill---and sometimes you have to give up and accept that the form of the expression will not be ``neat and compact.''

Operations on Polynomials, Rational Expressions, and Simplification of Expressions

A good way to gain familiarity with Mathematica's operations to do symbolic algebra is to look though the categories in the Built-in Functions section in the Help Browser.  Look though the names of functions  under Algebraic Computation--they have names that are fairly indicative of their purpose.

In[3]:=

PaulENomeal = ( 1 + 2 a + 3 x + 4 z ) ^ 4

Out[3]=

( 1 + 2 a + 3 x + 4 z ) 4

In[4]:=

FatPEN = Expand [ PaulENomeal ]

Out[4]=

1 + 8 a + 24 a 2 + 32 a 3 + 16 a 4 + 12 x + 72 a x + 144 a 2 x + 96 a 3 x + 54 x 2 + 216 a x 2 + 216 a 2 x 2 + 108 x 3 + 216 a x 3 + 81 x 4 + 16 z + 96 a z + 192 a 2 z + 128 a 3 z + 144 x z + 576 a x z + 576 a 2 x z + 432 x 2 z + 864 a x 2 z + 432 x 3 z + 96 z 2 + 384 a z 2 + 384 a 2 z 2 + 576 x z 2 + 1152 a x z 2 + 864 x 2 z 2 + 256 z 3 + 512 a z 3 + 768 x z 3 + 256 z 4

In[5]:=

Factor [ FatPEN ]

Out[5]=

( 1 + 2 a + 3 x + 4 z ) 4

In[6]:=

PaulinX = Collect [ FatPEN , x ]

Out[6]=

1 + 8 a + 24 a 2 + 32 a 3 + 16 a 4 + 81 x 4 + 16 z + 96 a z + 192 a 2 z + 128 a 3 z + 96 z 2 + 384 a z 2 + 384 a 2 z 2 + 256 z 3 + 512 a z 3 + 256 z 4 + x 3 ( 108 + 216 a + 432 z ) + x 2 ( 54 + 216 a + 216 a 2 + 432 z + 864 a z + 864 z 2 ) + x ( 12 + 72 a + 144 a 2 + 96 a 3 + 144 z + 576 a z + 576 a 2 z + 576 z 2 + 1152 a z 2 + 768 z 3 )

In[7]:=

Coefficient [ PaulinX , x , 0 ]

Out[7]=

1 + 8 a + 24 a 2 + 32 a 3 + 16 a 4 + 16 z + 96 a z + 192 a 2 z + 128 a 3 z + 96 z 2 + 384 a z 2 + 384 a 2 z 2 + 256 z 3 + 512 a z 3 + 256 z 4

In[8]:=

PaulSpiffedUp = Sum [ Simplify [ Coefficient [ PaulinX , x , i ] ] x ^ i , { i , 0 , 20 } ]

Out[8]=

81 x 4 + 108 x 3 ( 1 + 2 a + 4 z ) + 54 x 2 ( 1 + 2 a + 4 z ) 2 + 12 x ( 1 + 2 a + 4 z ) 3 + ( 1 + 2 a + 4 z ) 4

In[9]:=

Simplify [ PaulSpiffedUp ]

Out[9]=

( 1 + 2 a + 3 x + 4 z ) 4

In[10]:=

RashENell = ( x + y ) ( x - y ) + ( x - y ) ( y + x )

Out[10]=

x - y x + y + x + y x - y

In[11]:=

Apart [ RashENell ]

Out[11]=

- 2 - 2 x - x + y + 2 x x + y

In[12]:=

Together [ RashENell ]

Out[12]=

2 ( x 2 + y 2 ) ( x - y ) ( x + y )

In[13]:=

Apart [ Together [ RashENell ] ]

Out[13]=

- 2 - 2 x - x + y + 2 x x + y

In[14]:=

Numerator [ Together [ RashENell ] ]

Out[14]=

2 ( x 2 + y 2 )

In[15]:=

Simplify [ RashENell ]

Out[15]=

2 ( x 2 + y 2 ) x 2 - y 2

In[16]:=

Factor [ RashENell ]

Out[16]=

2 ( x 2 + y 2 ) ( x - y ) ( x + y )

One common hurdle is getting Mathematica  to remove roots:

In[17]:=

RootBoy = ( x + y ) 2

Out[17]=

( x + y ) 2

In[18]:=

Simplify [ RootBoy ]

Out[18]=

( x + y ) 2

Note in the following statement that "x ∈ Reals" means "x is a real number" and "&&" is the "Logical And" operator.

In[19]:=

Simplify [ RootBoy , x Reals && y Reals ]

Out[19]=

Abs [ x + y ]

In[20]:=

Simplify [ RootBoy , x 0 && y 0 ]

Out[20]=

x + y

Brute force; clever ,but not a good idea follows:

In[21]:=

RootBoy /. Sqrt [ ( expr_ ) ^ 2 ] expr

Out[21]=

x + y

Calculus

In[22]:=

AMessyExpression = Log [ x Sin [ x ] ] 1 x

Out[22]=

x Log [ x Sin [ x ] ]

In[23]:=

Limit [ AMessyExpression , x 0 ]

Out[23]=

0

In[24]:=

DMess = D [ AMessyExpression , x ]

Out[24]=

Log [ x Sin [ x ] ] + Csc [ x ] ( x Cos [ x ] + Sin [ x ] )

In[25]:=

Integrate [ DMess , x ]

Out[25]=

x Log [ x Sin [ x ] ]

In[26]:=

Integrate [ DMess , { x , 0 , } ]

Out[26]=

1 2 ( 2 - 2 + π - Log [ 4 ] + 2 Log [ 1 - 2 ] )

In[27]:=

( AMessyExpression /. x e ) - ( AMessyExpression /. x 0 )

:: indet : Indeterminate expression 0 ( - ) encountered. More… "Indeterminate expression \\!\\(0\\\\ \\(\\((\\(-\[Infinity]\\))\\)\\)\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::indet\\\"]\\)"

Out[27]=

Indeterminate

In[28]:=

( AMessyExpression /. x e ) - Limit [ AMessyExpression , x 0 ]

Out[28]=

e Log [ e Sin [ e ] ]

In[29]:=

Integrate [ Sin [ x ] / Sqrt [ ( x ^ 2 + a ^ 2 ) ] , x ]

Out[29]=

Sin [ x ] a 2 + x 2 x

In[30]:=

Integrate [ Sin [ x ] / Sqrt [ ( x ^ 2 + a ^ 2 ) ] , x , Assumptions a 0 ]

Out[30]=

Integrate [ Sin [ x ] a 2 + x 2 , x , Assumptions a 0 ]

In[31]:=

Integrate [ Sin [ x ] a 2 + x 2 , x , Assumptions Re [ a ^ 2 ] > 0 ]

Out[31]=

Integrate [ Sin [ x ] a 2 + x 2 , x , Assumptions Re [ a 2 ] > 0 ]

In[32]:=

UglyInfiniteIntegral = Integrate [ Sin [ x ] / Sqrt [ ( x ^ 2 + a ^ 2 ) ] , { x , 0 , } , Assumptions Re [ a ^ 2 ] > 0 ]

Out[32]=

1 2 π ( BesselI [ 0 , a ] - a StruveL [ 0 , a ] a 2 )

In[33]:=

N [ UglyInfiniteIntegral /. a 1 ]

Out[33]=

0.8730842426508671

Now we will introduce the Taylor expansion capabilities in Mathematica:

In[34]:=

Series [ AMessyExpression , { x , 0 , 4 } ]

Out[34]=

2 Log [ x ] x - x 3 6 + O [ x ] 5 SeriesData x 0 1 5 1 SeriesData x 0 2 x 0 -16 1 5 1

In[35]:=

FitAtZero = Series [ AMessyExpression , { x , 0 , 4 } ] // Normal

Out[35]=

- x 3 6 + 2 x Log [ x ]

In[36]:=

Plot [ { AMessyExpression , FitAtZero } , { x , 0 , 3 } , PlotStyle { { Thickness [ 0.02 ] , Hue [ 1 ] } , { Thickness [ 0.01 ] , Hue [ 0.5 ] } } ]

[Graphics:HTMLFiles/Lecture-04_1.gif]

Out[36]=

Graphics

Solving Equations

In[37]:=

TheEquation = a x ^ 2 + b x + c

Out[37]=

c + b x + a x 2

Note the use of Equal (==) rather than Set (=) in the following; using "=" will produce an error message.

In[38]:=

TheZeroes = Solve [ TheEquation == 0 , x ]

Out[38]=

{ { x - b - b 2 - 4 a c 2 a } , { x - b + b 2 - 4 a c 2 a } }

Note that the roots are given as Rules. Now we ask Mathematica to verify that the solutions it found are indeed roots to the specified equation. Here is a prototypical example of using Replace (/.) to accomplish this:

In[39]:=

TheEquation /. TheZeroes

Out[39]=

{ c + b ( - b - b 2 - 4 a c ) 2 a + ( - b - b 2 - 4 a c ) 2 4 a , c + b ( - b + b 2 - 4 a c ) 2 a + ( - b + b 2 - 4 a c ) 2 4 a }

In[40]:=

Simplify [ TheEquation /. TheZeroes ]

Out[40]=

{ 0 , 0 }

More examples of using Solve:

In[41]:=

a [ i_ ] := i + 1

In[42]:=

TheQuinticEquation = Sum [ a [ i ] x ^ i , { i , 0 , 5 } ]

Out[42]=

1 + 2 x + 3 x 2 + 4 x 3 + 5 x 4 + 6 x 5

In[43]:=

Solve [ TheQuinticEquation 0 , x ]

Out[43]=

{ { x Root [ 1 + 2 #1 + 3 #1 2 + 4 #1 3 + 5 #1 4 + 6 #1 5 & , 1 ] } , { x Root [ 1 + 2 #1 + 3 #1 2 + 4 #1 3 + 5 #1 4 + 6 #1 5 & , 2 ] } , { x Root [ 1 + 2 #1 + 3 #1 2 + 4 #1 3 + 5 #1 4 + 6 #1 5 & , 3 ] } , { x Root [ 1 + 2 #1 + 3 #1 2 + 4 #1 3 + 5 #1 4 + 6 #1 5 & , 4 ] } , { x Root [ 1 + 2 #1 + 3 #1 2 + 4 #1 3 + 5 #1 4 + 6 #1 5 & , 5 ] } }

In[44]:=

Quad1 = a x^2 + y + 3

Quad2 = a y^2 + x + 1

Out[44]=

3 + a x 2 + y

Out[45]=

1 + x + a y 2

In[46]:=

Solve [ { Quad1 0 , Quad2 0 } , { x , y } ]

Out[46]=

{ { x 1 2 a 2 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 - 1 2 a ( - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) ( - 8 3 a - 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 - ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 - 2 a 3 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) , y 1 2 ( - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) + 1 2 ( - 8 3 a - 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 - ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 - 2 a 3 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) } , { x 1 2 a 2 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 + 1 2 a ( - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) ( - 8 3 a - 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 - ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 - 2 a 3 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) , y 1 2 ( - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) - 1 2 ( - 8 3 a - 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 - ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 - 2 a 3 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) } , { x - 1 2 a 2 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 - 1 2 a ( - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) ( - 8 3 a - 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 - ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 + 2 a 3 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) , y - 1 2 ( - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) - 1 2 ( - 8 3 a - 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 - ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 + 2 a 3 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) } , { x - 1 2 a 2 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 + 1 2 a ( - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) ( - 8 3 a - 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 - ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 + 2 a 3 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) , y - 1 2 ( - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) + 1 2 ( - 8 3 a - 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 - ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 + 2 a 3 - 4 3 a + 4 2 1 / 3 ( 9 a 3 + 4 a 4 ) 3 a 3 ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 + ( 27 a 3 - 432 a 5 - 128 a 6 + 3 3 27 a 6 - 864 a 8 - 7168 a 9 - 2304 a 10 ) 1 / 3 3 2 1 / 3 a 3 ) } }

Numerical Solutions

In[47]:=

Integrate [ Sin [ x ] / Sqrt [ ( x ^ 2 + a ^ 2 ) ] , x ]

Out[47]=

Sin [ x ] a 2 + x 2 x

In[48]:=

Integrate [ Sin [ x ] / Sqrt [ ( x ^ 2 + a ^ 2 ) ] , { x , 0 , 1 } ]

Out[48]=

0 1 Sin [ x ] a 2 + x 2 x

In[49]:=

NIntegrate [ ( Sin [ x ] / Sqrt [ ( x ^ 2 + a ^ 2 ) ] ) /. a 1 , { x , 0 , 2 Pi } ]

Out[49]=

0.72204316269219

In[50]:=

Plot [ NIntegrate [ Sin [ x ] / Sqrt [ ( x ^ 2 + a ^ 2 ) ] , { x , 0 , 2 Pi } ] , { a , 0 , 10 } ]

[Graphics:HTMLFiles/Lecture-04_4.gif]

Out[50]=

Graphics

In[51]:=

Plot [ { AMessyExpression , FitAtZero } , { x , 0 , 3 } , PlotStyle { { Thickness [ 0.02 ] , Hue [ 1 ] } , { Thickness [ 0.01 ] , Hue [ 0.5 ] } } ]

[Graphics:HTMLFiles/Lecture-04_5.gif]

Out[51]=

Graphics

In[52]:=

NSolve [ AMessyExpression 0 , x ]

Solve :: verif : Potential solution { x 0. × 10 - 308 } (possibly discarded by verifier) should be checked by hand. May require use of limits. More… "Potential solution \\!\\({x \[Rule] 0``307.6526555685888}\\) (possibly discarded by verifier) should be checked by hand. May require use of limits. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Solve::verif\\\"]\\)"

Solve :: tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way. More… "The equations appear to involve the variables to be solved for in an essentially non-algebraic way. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Solve::tdep\\\"]\\)"

Out[52]=

NSolve [ x Log [ x Sin [ x ] ] 0 , x ]

In[53]:=

FindRoot [ AMessyExpression 0 , { x , .5 , 1.5 } ]

Out[53]=

{ x 1.11415714087193 }

In[54]:=

FindRoot [ FitAtZero 0 , { x , .5 , 1.5 } ]

Out[54]=

{ x 1.1076500783367882 }

In[55]:=

FindRoot [ AMessyExpression 0 , { x , 2.5 , 3 } ]

Out[55]=

{ x 2.7726047082659915 }

File Input and Output

In[56]:=

AMessyExpression >> AFile.m

In[57]:=

Clear [ AMessyExpression ]

In[58]:=

<< Afile.m

Out[58]=

x Log [ x Sin [ x ] ]

The next statement retrieves the content of Afile.m, but does not associate it with any name (in particular, with AMessyExpression!):

In[59]:=

AMessyExpression

Out[59]=

AMessyExpression

In[60]:=

AMessyExpression = << AFile.m

Out[60]=

x Log [ x Sin [ x ] ]

In[61]:=

AMessyExpression

Out[61]=

x Log [ x Sin [ x ] ]

The next statement introduces the "show file" command, !!

In[62]:=

!! Afile.m

x*Log[x*Sin[x]]

In[63]:=

Close [ ANewFileName ]

General :: openx : ANewFileName is not open. More… "\\!\\(\\\"ANewFileName\\\"\\) is not open. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::openx\\\"]\\)"

Out[63]=

Close [ ANewFileName ]

In[64]:=

AFileHandle = OpenWrite [ ANewFileName , FormatType OutputForm ]

Out[64]=

OutputStream [ ANewFileName , 14 ]

In[65]:=

RandomPairs = Table [ { Random [ ] , Random [ ] } , { i , 20 } ]

Out[65]=

{ { 0.31428945314450946 , 0.4386246010409837 } , { 0.8543814773139669 , 0.626076860969313 } , { 0.16905100584803526 , 0.9752787739431366 } , { 0.5520005163662806 , 0.33847393276272003 } , { 0.6706678760132773 , 0.5856658032621433 } , { 0.2527518858871625 , 0.1799646362510893 } , { 0.5032515844492167 , 0.9321874093146947 } , { 0.9119032142611405 , 0.5828387661370901 } , { 0.7751852761790115 , 0.33409043487706813 } , { 0.030177029939409183 , 0.4441921842018098 } , { 0.8425478380228674 , 0.20580099836725035 } , { 0.9816047741186846 , 0.9669091071050229 } , { 0.5282583848783579 , 0.7671763973262666 } , { 0.12722329680471778 , 0.3408322461357098 } , { 0.3592073790303226 , 0.7918976233831302 } , { 0.5752227804384372 , 0.0023583133729897644 } , { 0.6885395030170454 , 0.20623182012098676 } , { 0.32247089455127464 , 0.8223936771219005 } , { 0.1852879185678286 , 0.27404441080629205 } , { 0.41056768029013413 , 0.23955491098481035 } }

In[66]:=

Write [ AFileHandle , RandomPairs ]

In[67]:=

!! ANewFileName

{{0.314289, 0.438625}, {0.854381, 0.626077}, {0.169051, 0.975279},

  {0.552001, 0.338474}, {0.670668, 0.585666}, {0.252752, 0.179965},

  {0.503252, 0.932187}, {0.911903, 0.582839}, {0.775185, 0.33409},

  {0.030177, 0.444192}, {0.842548, 0.205801}, {0.981605, 0.966909},

  {0.528258, 0.767176}, {0.127223, 0.340832}, {0.359207, 0.791898},

  {0.575223, 0.00235831}, {0.68854, 0.206232}, {0.322471, 0.822394},

  {0.185288, 0.274044}, {0.410568, 0.239555}}

In[68]:=

Write [ AFileHandle , MatrixForm [ RandomPairs ] ]

In[69]:=

!! ANewFileName

{{0.314289, 0.438625}, {0.854381, 0.626077}, {0.169051, 0.975279},

  {0.552001, 0.338474}, {0.670668, 0.585666}, {0.252752, 0.179965},

  {0.503252, 0.932187}, {0.911903, 0.582839}, {0.775185, 0.33409},

  {0.030177, 0.444192}, {0.842548, 0.205801}, {0.981605, 0.966909},

  {0.528258, 0.767176}, {0.127223, 0.340832}, {0.359207, 0.791898},

  {0.575223, 0.00235831}, {0.68854, 0.206232}, {0.322471, 0.822394},

  {0.185288, 0.274044}, {0.410568, 0.239555}}
0.314289     0.438625

0.854381     0.626077

0.169051     0.975279

0.552001     0.338474

0.670668     0.585666

0.252752     0.179965

0.503252     0.932187

0.911903     0.582839

0.775185     0.33409

0.030177     0.444192

0.842548     0.205801

0.981605     0.966909

0.528258     0.767176

0.127223     0.340832

0.359207     0.791898

0.575223     0.00235831

0.68854      0.206232

0.322471     0.822394

0.185288     0.274044

0.410568     0.239555

In[70]:=

Close [ AFileHandle ]

Out[70]=

ANewFileName

Using Packages

Fortunately, others have gone to the trouble of writing files full of useful stuff--and you can load this stuff into Mathematica for your very own use.  Some people produce useful stuff and you can buy it, which is nice if you find it valuable--and you can write stuff and gain value by selling it, which might be even more nice.
Mathematica comes with a group of Standard Packages, that you can load in to do special tasks.  The Packages are listed under "Add-ons & Links" in the Help Browser.  For example, take a look at the specialized package under "Miscellaneous" called "World Plot"...

In[71]:=

<< Miscellaneous`WorldPlot`

In[72]:=

WorldPlot [ { { USA , France , Germany , Italy , Belgium , Luxembourg , Switzerland } , { RGBColor [ 1 , 0 , 0 ] , RGBColor [ 0 , 0.5 , 0 ] , RGBColor [ 0.5 , 0 , 0 ] , RGBColor [ 0 , 0 , 0 ] , RGBColor [ 0.4 , 0.4 , 0.1 ] , RGBColor [ 0 , 0 , 0.5 ] , RGBColor [ 0.9 , 0.6 , 0.6 ] } } ]

[Graphics:HTMLFiles/Lecture-04_6.gif]

Out[72]=

-WorldGraphics-

In[73]:=

WorldPlot [ { { USA , France , Germany , Italy , Belgium , Luxembourg , Switzerland } , { RGBColor [ 1 , 0 , 0 ] , RGBColor [ 0 , 0.5 , 0 ] , RGBColor [ 0.5 , 0 , 0 ] , RGBColor [ 0 , 0 , 0 ] , RGBColor [ 0.4 , 0.4 , 0.1 ] , RGBColor [ 0 , 0 , 0.5 ] , RGBColor [ 0.9 , 0.6 , 0.6 ] } } , WorldProjection -> Mollweide ]

[Graphics:HTMLFiles/Lecture-04_7.gif]

Out[73]=

-WorldGraphics-

In[74]:=

WorldPlot [ { { USA , France , Germany , Italy , Belgium , Luxembourg , Switzerland } , { RGBColor [ 1 , 0 , 0 ] , RGBColor [ 0 , 0.5 , 0 ] , RGBColor [ 0.5 , 0 , 0 ] , RGBColor [ 0 , 0 , 0 ] , RGBColor [ 0.4 , 0.4 , 0.1 ] , RGBColor [ 0 , 0 , 0.5 ] , RGBColor [ 0.9 , 0.6 , 0.6 ] } } , WorldProjection LambertAzimuthal ]

[Graphics:HTMLFiles/Lecture-04_8.gif]

Out[74]=

-WorldGraphics-


Created by Mathematica  (September 13, 2005) Valid XHTML 1.1!