1. Getting Started

Legal Notice, Disclaimer, and Book Ordering Information:

Null

Setup

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

1.3 Functions and Procedures

1.3.1  User-defined Functions

\(f[k_, y_]\  := \ N[BesselJ[k, y], 2]; 
f[1, 2]\)

Postfix notation

\(g[k_, y_]\  := \ BesselJ[k, y]\  // \ N[#, 2]&; 
g[1, 2]\)

1.3.2  Discontinuous Functions

step1[x_]  :=  -1  /;  x <= 0step1[x_]  :=  1  /;  0 < x

\(step2[x_\  /; \ x <= 0]\  := \ 
      \(\(-1\)
step2[x_\  /; \ 0 < x]\  := \ 1\)\)

Plot[step1[x], {x, -1, 1}];

\({Timing[\ Table[step1[x], {x, \(-2\), 2,  .0005}]] // First, 

      Timing[\ Table[step2[x], {x, \(-2\), 2,  .0005}]] // First}\)

Note:  Apparently Mathematica Version 3.0.1 does not allow the form used for step2 above.

1.3.3  Nonanalytic Functions

D[Conjugate[ f[y] ],  y]

Note: Mathematica attempts to treat Conjugate as an analytic function and fails.

\(Unprotect[Conjugate]; 

    D[\ Conjugate[x___], \ y___]\  ^:= \ Conjugate[D[x, y]]\)Protect[Conjugate];

D[Conjugate[ f[y] ],  y]

1.3.4  Rules

\(\(i /: i^2\  = \ \(-1\); 
i /: i^3\  = \ \(-i\); 
i /: i^4\  = \ 1; 

    i /: i^n\  := 
      i^Mod[n, 4]\  /; \ \ IntegerQ[n]\  && \ \((n < 0\  || \ 4 > n)\); \ 
    \)\)

Table[i^n, {n, -8, 8}]

Table[Mod[n, 4], {n, -8, 8}]

\(Unprotect[Cos, Sin]; 

    Cos /; \ Cos[n_\ Pi]\  := \ \((\(-1\))\)^n\  /; \ IntegerQ[n]; 

    Sin /; \ Sin[n_\ Pi]\  := \ 0\ \ \ \ \ \ \ \ \ \ \ \ \  /; \ IntegerQ[n]; 
    
Protect[Cos, Sin]; \)

IntegerQ[n]  ^=  True;

{Cos[n Pi],  Sin[n Pi]}

1.3.5  Procedures

\(\(prod[x_, n_]\  := \ 
      Module[{s, temp1, temp2}, 

        		\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
        temp1 = Product[\((x - s)\)^\((s)\), {s, 1, n, 2}]; 

        		\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ temp2 = temp1\  // ExpandAll; 

        				\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Return[temp2]
		]; 
prod[x, 2]
\)\)

prod[x, 3]

\(\(factor[equation_]\  := 
	\ \ \ \ \ 
      Module[{temp1}, 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
        temp1\  = \ \((x /. NSolve[equation, x])\); 

        \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
        Return[\ \ Times@@\((x - temp1)\)\  == \ 0]
]; \)\)

factor[-1  +  3  x  - 3  x^2  +  x^3  -  x^5  == 0 ]  // 
      N[#, 3]&