910 likes | 1.05k Views
Symbolic Software Lab Fall Semester 2010 Dr. Stefan Maubach. What is this course about?. Part I: Three weeks of Mathematica Part II: One week of. evaluation. 4 weekly assignmenets, each 25% each due on the Wednesday 23:59 of the following week. late homeworks policy.
E N D
What is this course about? • Part I: Three weeks of Mathematica • Part II: One week of
evaluation • 4 weekly assignmenets, each 25% • each due on the Wednesday 23:59 of the following week. • late homeworks policy
Story of Mathematica • Steven Wolfram • born 1959 in London • received Ph.D. from Caltech at the age of 20 • Mathematica released in 1988 • Interest in cellular automata • A New Kind of Science released in 2002 • Computational knowledge engine: • Wolfram Alpha • More on http://en.wikipedia.org/wiki/Wolfram_Alpha
What can I do with Mathematica? • Computer algebra system • 2D and 3D visualization • statistical analysis • image processing • tons of other things!
Two parts • Front End interface • Kernel calculator
Kernel Kernel interpretes the Mathematica expressions and return the result
Notebook cells
Arithmetic • In[1]: = 2+(3*4) • Press Shift + Enter • Out[1]= 14 • In[2]:=Sqrt[16] • Out[2]=4 • In[3]=a a • Out[3]=a^2
Library of Math Functions • Constants: PiE • Trigonometric : Sin[x] Cos[x] Tan[x] • Exponential/ Logarithm: Exp[x] Log[x] • Number theoretic functions: GCD[x,y] Prime[n] • Numerical functions: Abs[x] Floor[x]
Exercises Look up the following functions: RGBColor Dashing Thickness AxesRatio
Graphics I • Plot[Sin[x]+Exp[x],{x,0,1}] • Plot[Cos[x],{x,0,1}] • ParametricPlot[{Sin[t],t},{t,-1,1}] • Plot[{E^x,x^E},{x,0,6}] • Plot[{E^x,x^E},{x,0,6},PlotStyle->{{..},{..}}]
Options • AspectRation -> 1 • Axes --> Automatic • Thickness • RGBColor[0.8,0.2,0.2] • Dashing[{0.04}] • Experiment! Options[Plot]
define your own function • f [ x_ ]=Sin[x]+Cos[x] • f[Pi]=-1
Lists • a={2,3,5,7,11} • b={{2,3},{4,5},6}
accessing a list myprimes={2,3,5,7,11,13} myprimes[[ 2]] 3 myprimes[[-1]] myprimes[[{2,4}]]
accessing a list p={24,56,radio,5,7,11,13} First[p] Last[p] Drop[p,3] myprimes[[{2,4}]]
manipulating a list mll={2,{3,5},7,{11,x},13} Flatten[mll] {2,3,5,7,11,x,13}
manipulating a list Check the following functions: Append Prepend Insert Delete Drop
creating a list Table[x^2,{x,2,5}] {4,9,16,25}
Listable functions Sqrt[{1,4,9}] {1,2,3}
Other Listable functions {1,2,3}^2 {1,4,9}
non-listable functions Map[f,{a,b,c,d}] {f[a],f[b],f[c],f[d]}
Other useful functions Select Select[{1,2,3,4,6},PrimeQ] {2,3}
Other useful functions Length Length[{1,2,3,4,6}] 5
Other useful functions Count Count[{1,2,1,4,1},1] 3
Defining functions f[x_]:=x^3-1 f[2] 7
Boolean functions PrimeQ TrueQ
anonymous functions (#^2-1)&[5] 24
anonymous functions PrimeQ[#!+1]&[3] True
anonymous functions (#1^2+#2^2)&[1,2] 5
Graphics Graphics Plot[Sin[x],{x,Pi,2 Pi}]
Graphics Graphics Plot[{Sin[x],Cos[x]},{x,Pi,2 Pi},Frame->True, FrameStyle->Thick,Background->LightGreen,PlotLabel->Graphs ]
Functional Programing Any program is a function
Examples • Consider {{a,1},{b,2},{c,3},{d,4}} • Question: How to transpose it?
Solution 1 • temp=lis • Do[{temp[[i,1]],temp[[i,2]}={lis[[i,2]],lis[[i,1]]},{i,1,Length[lis]}]; • temp
Solutions 2 • Table[{lis[[i,2]],lis[[i,1]]},{i,1,Length[lis]}]
Solution 3 • Map[Reverse,lis]
Everything is a function! Everything is a function! • {1,2,3} List[1,2,3] • a+b Plus[a,b] • c^2 Power[c,2]
Examples • Times[a,b] • FullForm[a+b] • Plus[a,b]