(*************************************) (* Short introduction to Mathematica *) (* Karl w Broman, 27 April 2007 *) (*************************************) (********** first stuff **********) 5^12 %1 ^ (1/12) % + a L = 3 L L = 3; 20 L 2 m + 3 m %% %8 (********** help **********) ?Factor* ?FactorInteger ??FactorInteger ?*Graphic* ?*Plot* ?@ (********** packages **********) GramSchmidt[{{1,1,0}, {0,2,1}, {1,0,3}}] Remove[GramSchmidt] << LinearAlgebra`Orthogonalization` GramSchmidt[{{1,1,0}, {0,2,1}, {1,0,3}}] (********** numbers **********) 5 * 10 5 10 a10 a 10 1/2 + 2/144 1/2 + 2.0/144 Sqrt[27] Sqrt[27.0] N[Sqrt[27]] (********** constants **********) E Pi N[E,25] N[Pi,100] (********** algebra **********) Expand[ (x + 2y + z)^2 ] Factor[ % ] Together[ 1/(1+2x) - 2/(2+3x) ] Apart[ % ] (********** solving equations **********) f = x^3 - 3 x^2 - 17x + 51; soln = Solve[f == 0, x] f /. soln NRoots[ f == 0, x ] (********** simple example **********) Vg = a^2 / 2 + d^2 / 4; Ve = Vg (1-hsq)/hsq; a = 4d; hsq = 6/10; Solve[Ve == 1, d] (********** solving systems **********) eqn1 = 2 p1 + 2 p2 == 1; eqn2 = p1 == (1-r) p1 + p2 / 2; Solve[ {eqn1, eqn2}, {p1, p2}] (********** nonlinear example **********) N[ Solve[ {x^2 == 2y + 2, x == y^2 + 1}, {x,y} ] ] << Miscellaneous`RealOnly` Solve[ {x^2 == 2y + 2, x == y^2 + 1}, {x,y} ] (********** series **********) Sum[ Exp[-mu] mu^n / Factorial[n], {n, 0, Infinity} ] Sum[ n Exp[-mu] mu^n / Factorial[n], {n, 0, Infinity} ] Sum[ (n - mu)^2 Exp[-mu] mu^n / Factorial[n], {n, 0, Infinity} ] Sum[ p^k, {k, 0, n} ] Sum[ p^k, {k, 1, n}] (********** limits **********) Limit[ Sin[x]/x, x -> 0 ] Limit[ 1/x, x -> Infinity ] Limit[ 1/x, x->0, Direction -> -1 ] Limit[ 1/x, x->0, Direction -> 1 ] (********** integrals & derivatives **********) Integrate[ x^4 Cos[x], x ] D[%, x] Simplify[%] Integrate[ Exp[x], {x, -1, 1} ] Together[%] (********** another example **********) Integrate[ 3 Sqrt[3]/(2 Pi) / (r^2 + r(1-r) + (1-r)^2), r] % /. r -> 0 Solve[%1 + 1/2 == 0.025, r]