Professional Documents
Culture Documents
4050
Mathematica
Mathematica Mathematica
2.1
Mathematica
Mathematica
Mathematica
3 + 4 5 Mathematica
Mathematica
Head
Head7, Head1 7, Head7.0, Head7 2
Integer, Rational, Real, Complex
In[1]:=
Out[1]=
Mathematica
In[2]:= Head1, 2, 3, 4, 5
Out[2]= List
In[3]:= Head
Out[3]= Image
Mathematica
graph 2.1
2 2Mathematica.nb
2.1
Integer 3, 0, 28,...
1 8
Rational , , ...
2 9
Real 0.2348
Complex 54,...
String ""
Symbol Plot, myFun,...
SparseArray SparseArray4,3,3
Out[150]=
Graph
Image
Head
In[6]:= Part1.2345, 1
Part::partd : 1.23451 .
Out[6]= 1.23451
In[7]:= Headx31
Out[7]= Symbol
In[8]:= HeadIntegrate
Out[8]= Symbol
Mathematica
Head, Head, HeadEulerGamma, HeadKhinchin
Symbol, Symbol, Symbol, Symbol
In[9]:=
Out[9]=
9
In[10]:= Head"Mathematica"
Out[10]= String
2Mathematica.nb 3
In[11]:= Head
Out[11]= Graph
In[12]:= AtomQ
Out[12]= True
Mathematica SparseArray
mat SparseArrayi_, i_ 1, 4, 4
SparseArray4, 4, 4
In[13]:=
Out[13]=
In[14]:= MatrixFormmat
1 0 0 0
0 1 0 0
Out[14]//MatrixForm=
0 0 1 0
0 0 0 1
In[15]:= AtomQmat
Out[15]= True
8.3
Mathematica
h
ei
he1 , e2 , ..., en
Head Head
In[16]:= Heada b c
Out[16]= Plus
FullForm
In[17]:= FullForma b c
Out[17]//FullForm= Plusa, b, c
In[18]:= FullForma, b, c
Out[18]//FullForm= Lista, b, c
Plus
List Mathematica
FullForm Mathematica
4 2Mathematica.nb
FullForm Mathematica
4
FullForm
In[19]:= Lengtha b c
Out[19]= 3
In[20]:= expr Sinx a x2 b x c
Out[20]= c b x a x2 Sinx
Times Sin[x]
In[21]:= Headexpr
Out[21]= Times
2
In[22]:= Lengthexpr
Out[22]= 2
FullForm Plus[...]
Sin[x] Times
In[23]:= FullFormexpr
Out[23]//FullForm= TimesPlusc, Timesb, x, Timesa, Powerx, 2, Sinx
Head
In[24]:= HeadIntegrate
Out[24]= Symbol
In[25]:= Head""
Out[25]= String
In[26]:= Head2
Out[26]= Integer
In[27]:= Head5.21
Out[27]= Real
FullFrom
In[28]:= FullFormf
Out[28]//FullForm= f
FullForm
5
In[29]:=
7
Out[29]//FullForm= Rational5, 7
Part
a + b a
In[30]:= Parta b, 1
Out[30]= a
2Mathematica.nb 5
b
In[31]:= Parta b, 2
Out[31]= b
In[32]:= FullForma b
Out[32]//FullForm= Plusa, b
In[34]:= Part" ", 1
Part::partd : 1 .
Out[34]= 1
expr[[1]]
Part[expr , 1]
In[35]:= 3 4 1
Part::partd : 3 4 1 .
Out[35]= 3 4 1
Mathematica
Part
In[36]:= Appendw x y, z
Out[36]= wx yz
FullForm
In[37]:= FullFormw x y
Out[37]//FullForm= Plusw, Timesx, y
z w + x y z Plus
In[38]:= Appendfa, b, c
Out[38]= fa, b, c
TreeForm
Plus , c bx a x2
6 2Mathematica.nb
In[39]:= TreeForma x2 b x c
Plus
c Times Times
Out[39]//TreeForm=
b x a Power
x 2
In[40]:= Heada x2 b x c
Out[40]= Plus
Plus
In[41]:= Parta x2 b x c, 2
Out[41]= bx
In[42]:= FullForm
Out[42]//FullForm= Timesb, x
In[43]:= Partb x, 2
Out[43]= x
Part
In[44]:= Parta x2 b x c, 2, 2
Out[44]= x
Part
Numerator , Denominator
3 3
In[45]:=
3, 4
4 4
Out[45]=
MantissaExponent3333.14152
0.333314, 4
In[46]:=
Out[46]=
2Mathematica.nb 7
Re3 4 , Im3 4
3, 4
In[47]:=
Out[47]=
VertexListCompleteGraph5, EdgeListCompleteGraph5
1, 2, 3, 4, 5,
In[48]:=
1 2, 1 3, 1 4, 1 5, 2 3, 2 4, 2 5, 3 4, 3 5, 4 5
Out[48]=
Mathematica
expr1 && expr2 && expr3 Mathematica expri
1.
In[51]:= 123.456
Out[51]= 123.456
2.
In[52]:= mysymbol
Out[52]= mysymbol
3.
4. Hold
5.
WMDC
Plus[2, 2]
In[53]:= FullForm2 2
Out[53]//FullForm= 4
Plus
Hold
In[54]:= FullFormHoldForm2 2
Out[54]//FullForm= HoldFormPlus2, 2
HoldForm FullForm
Hold
8 2Mathematica.nb
AttributesPlot
HoldAll, Protected, ReadProtected
In[55]:=
Out[55]=
PlotTablexi , i, 2, 8, 2, x, 1, 1,
PlotStyle Dashing.01, Dashing.03, Dashing.05, Dashing.07
In[56]:=
1.0
0.8
0.6
Out[56]=
0.4
0.2
Plot
Table Plot HoldAll
Hold Evaluate Plot Evaluated
PlotEvaluate Tablexi , i, 2, 8, 2, x, 1, 1,
PlotStyle Dashing.01, Dashing.03, Dashing.05, Dashing.07
In[57]:=
1.0
0.8
0.6
Out[57]=
0.4
0.2
Defer
In[58]:= Defer2 2
Out[58]= 22
In[59]:= DeferFullForm2 2
Out[59]= Plus2, 2
Defer
2Mathematica.nb 9
In[60]:= Plus2, 2
Out[60]= 4
1. a (b + c)
2. Times[a, Power[Plus[b, c], -1]]
3. a x2 + b x + c b
4.
(a) x2 + y) z / w)[[2, 1, 2]]
Mathematica
a
In[61]:= a N2
Out[61]= 6.28319
Mathematica a
a
In[62]:= Cosa
Out[62]= 1.
a ?a
In[63]:= ?a
Global`a
a 6.28319
a=N[2 ]
a
f x_
x
1
In[64]:= fx_
1x
1
Out[64]=
1x
f[x_] Mathematica
4 f[x_] f[]
f x
10 2Mathematica.nb
In[65]:= f.1
Out[65]= 0.909091
In[66]:= f1
1
Out[66]=
2
In[67]:= f2
1
Out[67]=
1 2
In[68]:= f
1
Out[68]=
f x_
In[69]:= Cleara, f
Set[lhs, rhs]
lhs rhs
rand101
In[71]:= rand1 RandomReal
Out[71]= 0.277545
Mathematica
SetDelayed[lhs, rhs]
2Mathematica.nb 11
lhs : rhs
In[72]:= DeferFullFormx : 5
Out[72]= SetDelayedx, 5
rand1 rand2
In[73]:= rand2 : RandomReal
rand2
5
Tablerand1, 5
0.277545, 0.277545, 0.277545, 0.277545, 0.277545
In[74]:=
Out[74]=
In[75]:= ? rand1
Global`rand1
rand1 0.277545
rand2
Tablerand2, 5
0.244559, 0.321648, 0.809704, 0.432592, 0.0759782
In[76]:=
Out[76]=
Global`rand2
rand2 : RandomReal
Mathematica
Mathematica
Mathematica Mathematica
Mathematica
?name
In[78]:= ? Map
In[79]:= ? rand1
Global`rand1
rand1 0.277545
Set
01
SetDelayed SetDelayed
In[80]:= ? rand2
Global`rand2
rand2 : RandomReal
SetDelayed Set
SetDelayed
SetDelayed
Set Set
Mathematica Clear[name]
1 + x + x2 f
In[81]:= fx_ : 1 x x 2
f
In[82]:= fx_, y_ : x y
1
In[83]:= fx_, y_, z_ :
xy z
f ?f
In[84]:= ?f
Global`f
fx_ : 1 x x2
fx_, y_ : x y
1
fx_, y_, z_ :
xyz
In[85]:= funx_ : Absx
In[87]:= fun 12
Out[87]= 12
In[88]:= fun2, 3
Out[88]= 13
In[89]:= fun2 3 I
Out[89]= 13
In[90]:= fun"string"
Out[90]= Absstring
In[91]:= funa, b, c, d
Out[91]= a2 c2 , b2 d2
4
In[92]:= Clearx, f, g, n, fun
1. ?
(a) randLis1[n_] := RandomReal[1, {n}]
(b) randLis2[n_] := (x = RandomReal[]; Table[x, {n}])
(c) randLis3[n_] := (x := RandomReal[]; Table[x, {n}])
(d) randLis4[n_] := Table[RandomReal[], {n}]
2. f g
In[95]:= f2
1 x 1 1 x2
Out[95]=
x
In[96]:= g2
Out[96]= 1 x 1 x2
3. log
log a b log a logb;
a
log loga logb;
log an n log a .
b
4. g(x) -2 0
14 2Mathematica.nb
1 x 22 2 x 1
gx
1 x2 x 0
PrimeQ
In[97]:= PrimeQ231 1
Out[97]= True
In[98]:= OddQ21
Out[98]= True
In[99]:= EvenQ21
Out[99]= False
IntegerQ
5
In[100]:=
9
Out[100]= False
NumerQ True
IntegerRationalReal Complex
In[103]:= NumberQ3.2
Out[103]= True
In[104]:= NumberQ
Out[104]= False
In[105]:= VectorQ23 1, 27 1, 231 1, PrimeQ
Out[105]= True
In[106]:= AtomQ""
Out[106]= True
2Mathematica.nb 15
In[107]:= ListQa, b, c
Out[107]= True
SymmetricMatrixQ 2 4 5
1 2 3
In[108]:=
3 5 6
Out[108]= True
1 1 1
In[109]:= PolynomialQ , x
x x2 x3
Out[109]= False
In[110]:= ConnectedGraphQ
Out[110]= True
In[111]:= IntervalMemberQInterval2, 3,
Out[111]= False
True
False Mathematica Equal( == ) Unequal( ) Greater (>) Less(<)
GreaterEqual() LessEqual ()
In[112]:= 75
Out[112]= False
6
In[113]:= 3 74
2
Out[113]= True
Simplify
x4 1
In[114]:= x2 1
x2 1
Out[114]= True
3 ( 7 - 4) (3 7 ) -4
2.2
In[115]:= 4 5 && 8 1
True
5.8 TruthTable
BooleanTableA B, A, B
True, False, False, False
In[116]:=
Out[116]=
2.2
16 2Mathematica.nb
x y Equalx,y
x y Unequalx, y
Out[147]= x y Greaterx, y
x y Lessx, y
x y GreaterEqualx, y
x y LessEqualx,y
Or || ( )
4 3 3
6
In[118]:=
2
Out[118]= True
0 0.0001
22
In[119]:=
7
Out[119]= False
BooleanTableA B, A, B
True, True, True, False
In[120]:=
Out[120]=
AB
In[121]:= True True
Out[121]= True
2.3
2.3.
x x Notx
x&&y xy Andx,y
xy&&x&&y
Out[122]= xy xy Orx,y
xy Xorx,y
xy xy Norx,y
xy xy Impliesx,y
Mathematica Xor
In[123]:= XorTrue, True
Out[123]= False
In[124]:= XorTrue, False
Out[124]= True
BooleanTableA B, A, B
False, True, True, False
In[125]:=
Out[125]=
2.4
BitOr[x, y] x y 21
19
2Mathematica.nb 17
BitXor[x, y] x y
In[129]:= BaseFormBitOr2^^10101, 2^^10011, 2
Out[129]//BaseForm= 101112
2.4.
BitAndx,y xy
Out[130]= BitOrx, y xy
BitNotx x
BitXorx,y xy
5.8
1. -11True
2. CharacterQ[str]str
3. Natural[n]n
4. SubsetsQlis1 , lis2 ] lis1 lis2 {}
5. CompositeQ
Mathematica
Attributes
AttributesPlus
Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected
In[131]:=
Out[131]=
Flat Plus
a + (b + c) = (a + b) +c Mathematica
Plus[a, Plus[b, c]] Plus[Plus[a, b], c](flat) Plus[a, b, c] Mathematica
Flat
In[132]:= PlusPlusa, b, c
Out[132]= abc
In[133]:= thin
Out[133]= hint
In[134]:= x3 x5 x4 x2 1 x
Out[134]= 1 x x2 x3 x4 x5
In[135]:= x3 y2 y7 x5 y x4 y9 x2 1 x
Out[135]= 1 x x4 y x3 y2 x5 y7 x2 y9
In[136]:= TraditionalFormx3 x5 x4 x2 1 x
Out[136]//TraditionalForm=
x x x3 x2 x 1
5 4
Protected
( Protected
Plus Listable NumericFunction
WMDC
Orderless
In[137]:= fb, e, t, s
Out[137]= fb, e, t, s
SetAttributes f Orderless
In[138]:= SetAttributesf, Orderless
In[139]:= fb, e, t, s
Out[139]= fb, e, s, t
Clear
In[140]:= Clearf
In[141]:= ?f
Global`f
Attributesf Orderless
ClearAttributes[] ClearAll[]
In[142]:= ClearAllf
In[143]:= ?f
Global`f
5.26.2 SetAttributes
2Mathematica.nb 19
1. Mathematica
osyi2 + 3 f
In[144]:= fx_ y_ : x 2 y 2
In[145]:= f2 3
Out[145]= f5
Hold f
In[146]:= f2 3
Out[146]= f5
2. (**)