(*   Programs for Mathematica Exercises in Introductory Physics
     by Rodney L. Varley, Hunter College, New York City
     rvarley@shiva.hunter.cuny.edu
     Copyright: Prentice Hall              
     
     These programs require the software application, 
     Mathematica published by Wolfram Research, Inc. 
     Champaign, IL.                                     *)

(*     Module #1:  Introduction to Mathematica      

       Mathematica will perform the calculations below if
       you select the cell by "clicking on it".  Then 
       choose "Evaluate Cell" from the "Evaluation" menu.
       
       The first calculation might take a tad longer, 
       depending upon your computer, but subsequent 
       calculations are almost immediate.
       
       Comments are indicated (*  comment  *) and are
       ignored by Mathematica.  The comments are only of 
       interest to the human reader.
       
       It is recommended you try typing the calculation
       yourself instead of using those provided here, as
       in that way you will learn more about the syntax
       of Mathematica. ONLY if you get stuck and cannot
       get a result in the textbook, should you resort
       using the calculations and programs provided here.
       
       The calculations in this modules involve only one
       line.  The programs in later modules are a little
       longer and the programs here should help you should
       you get results different from those found in the 
       textbook.  *)

(*     Section 1: Calculator features of Mathematica           
       Addition, Subtraction, Multiplication and Division  *)

2 + 7

2 - 7

6*17

6 17

(3+8)*4

2/5

2./5

(*    The Numerical Function N[ ]                  *)

N[2/5]

(*    A number raised to a power                   *)

5^2

(*    pi,  the ratio of a circle’s circumference to its diameter *)

Pi

N[Pi]

N[Pi,80]

(*    The Square Root function                      *)

Sqrt[12.]

Sqrt[12]

Sin[Pi]

Sin[30*Pi/180]

N[Sin[30*Pi/180]]

(*    ASSIGNMENT of a Numerical Value to a Symbol    *)

b = 5

Print[b]

Print["b = ", b]

(*     Scientific Notation; examples       *)

z=7.5*(10^9)

y=3.4*(10^-7)

(*     Continuation of a Line     *)

2.35 + 4.86 + 3.95 +
    9.80 + 6.72

2.35 + 4.86 + 3.95
    + 9.80 + 6.72

(*    Capital Letters start all built-in functions, so  use Small Letters to start user-defined functions  *)

y=3.0;

?y

?Y

(*    Function Definitions involve adding a “blank,” _ , after a variable name     *)

f[x_] = 5*x + b

f[2.0]

f[x=2.0]

?f

b = 10;
f[2.0]

(*    Delete a Function Definition   *)

Clear[f]

?f

(*   A different way to define a function establishes EQUIVALENCE, as opposed to ASSIGNMENT. This has the advantage of remaining sensitive to subsequent changes in a right-side constant, b *)

g[x_] := 5*x + b

g[2.0]

b=15.

g[2.0]

(*     Graph of the Sine function with various options *)

Plot[ Sin[x], { x, 0, 2 Pi}]

Plot[ Sin[x], { x, 0, 2 Pi}, GridLines->Automatic]

plot1 = Plot[ 3*x + 7, {x, -3, 5 },
                    GridLines->Automatic]

plot2 = Plot[ g[x], {x, -3, 5 }, 
              PlotStyle->Dashing[{0.05}],
              GridLines->Automatic]

Show[plot1,plot2]