Fight Club, 8 Sept. 2011

Solving equations

Solve[4 == x^2,x]

Clear[x]

theSols = Solve[x^2+a x+1==0,x]

branches = x/.theSols

Plot[branches,{a,-10,10}]

Solve[Log[1/x]== Exp[-x], x]

finding numerical solutions

Plot[{Log[1/x],Exp[-x]},{x,0,10}]

FindRoot[Log[1/x]== Exp[-x],{x,1}]

What are those parenthetical things?

Round parenthesis  (   )
are for grouping things

2 a + b/2 + 3

2 a + b/(2 + 3)

2( a + b/2 + 3)

Curlies {   }
curiies are lists of things

{1,2,3,4}

here a list appears as an argument and as a result...

Table[i^2,{i,1,5,.5}]

Brackets [   ]
Brackets are for function calls

Cos[Pi/12]

Plot[x^2,{x,0,1}]

doPlot[a_] := Plot[Sin[2 Pi a x],{x,0,1}]

doPlot[3]

doPlot[5]

Double Brackets [[ ]]

double brackets are for picking things out of lists

{1,2,3,f,g,h}[[5]]

alist = {1,2,3,{s,d,1},1,3}

alist[[4]]

alist[[4,1]]

Counting Integers

what are patterns

test ={a,b,d, e, f , f + e, 2f}

test/.{a_ + b_ -> Sin[ b a]}

Count[test,2 t_]

Count[  
  test          ,

b]

construcintg and intersieting list to pcik from

theList = Flatten[Table[Sin[n Pi/m],{n,1,5},{m,1,5}]]

Count[theList,_Integer]

Count[theList,_Negative]

FullForm[theList]

Count[theList,_Times]

Count[theList,_Integer]

IntegerQ[3.4]

IntegerQ[24452]

Count[theList,_?IntegerQ]

Count[theList,_?PrimeQ]

aNewList= Table[Fibonacci[k],{k,1,30}]

Count[aNewList,_?PrimeQ]

Uze of the semicolin

putting a ton of command on one line..

a = 3
 a = a + b
 a= a^a

a = 3;
 a = a + b
 a= a^a

a = 3; a = a + b; a= a^a

Suppresssing extraneous output

listOfSquares = Table[i^2,{i,1,100}]

listOfSquares = Table[i^2,{i,1,100000}];

Making a bigger cubic lattice...

I need a list of sphere coordinates.

coordinates = Table[i {1,0,0} + j {0,1,0} + k{0,0,1},{i,1,5},{j,1,5},{k,1,5}];

coordinates= Flatten[coordinates,2]

Graphics3D[
Table[Sphere[coordinates[[i]],.5],{i,1,Length[coordinates]}]]

Graphics3D[
Table[
{Hue[i/Length[coordinates]],
Sphere[coordinates[[i]],.5]},{i,1,Length[coordinates]}]]

Graphics3D[
Table[
{Hue[RandomReal[]],
Sphere[coordinates[[i]],.5]},{i,1,Length[coordinates]}]]

Graphics3D[
Table[
{Hue[RandomReal[{0,.5}]],
Sphere[coordinates[[i]],.5]},{i,1,Length[coordinates]}]]

Graphics3D[
Table[
{Hue[RandomReal[{.5,1}]],
Sphere[coordinates[[i]],.5]},{i,1,Length[coordinates]}]]

Graphics3D[
Table[
{Hue[RandomReal[{.5,1}]],
Sphere[coordinates[[i]],RandomReal[{.5,1}]]},{i,1,Length[coordinates]}]]

randomSpherePositions = RandomReal[{-10,10},{100,3}];

Graphics3D[Table[Sphere[randomSpherePositions[[i]],.5],{i,1,100}]]

Graphics3D@(Sphere[#,.5]&/@randomSpherePositions)

Solcing a differential equation

lhs = D[y[x],x] x + y[x]

rhs= x

ode = lhs==rhs

DSolve[{ode,y[1] == 10},y[x],x]

thsol = y[x]/.DSolve[{ode,y[1] == 10},y[x],x]

Plot[thsol,{x,0,3}]

D[y[x],{x,2}] + α y[x] == 0

DSolve[D[y[x],{x,2}] + α y[x] == 0,y[x],x]

DSolve[D[y[x],{x,2}] + α y[x] ==Sin[ω x],y[x],x]

Derivatives...

D[y,x]

D[y[x],x]

D[y[x,z],x]

D[y[z],x]