Вы находитесь на странице: 1из 6

Mathematica

I .
,
(File, Edit, Sell, Format,Input,Kernel .). ,
,
(notebook). ,
.
.
.
, ,
File->new, File->open, File->save
( *.nb)
*
File->Palettes->
* Basic input.

1)
3 : 1) , 2)
, 3) , ..
(Cells)
, **:
(Format->Style)

input
.
In[45]:= t = 3 + 2
.
output

Out[45]= 5
title, subtitle, text ... , ..

** , , .., , text
: Cell->Cell Properties->Cell Evaluatable.

, Save .
Edit->Preferences, LookUp : WindowToolbars
LookUp. WindowToolbars "EditBar" Apply.

2) . .
input.

<Shift> <Enter>.
Kernel->Evaluation->Evaluate Notebook.
, ;.
3)

a=b ( Set[a,b])
a b
a:=b ( SetDelayed[a,b])
a b
ClearAll[a]
a
4)
In[494]:=

F@x_D = 2 x2;

Out[494]=

18

F@3D

3) 4): 3
1) In[477]:= ClearAll@F, xD;
2) In[467]:= ClearAll@F, xD;
x = 4;

3) In[472]:= x = 4;

F@x_D :=

x
3 1;
2
ClearAll@F, xD;
F@8D
x

x = 4;

x
F@x_D = 3 1;
2
F@8D
x

F@x_D :=

F@8D
x

x
3 1;
2

Out[480]=

Out[470]=

11

Out[475]=

F@8D

Out[481]=

Out[471]=

Out[476]=

5) ,,

a
a
F@xD x
[Ctrl + /]

a [ctrl +^]

[ctrl +@]

[ctrl +-]

ESC int ESC F[x] ESC dd ESC x

ESC prod ESC

6) : ESC <> ESC

=2.7

=3.14

<>

ee

pi

=(-1)1/2

ii

inf

th

Ps

ps

II.
) 1- 2- : m={1,3,5,r,t};
M={{a11,a12} ,{a21,a22}};
: m=List[1,3,5,r,t]; : n={{1,3,5,r,t}};
2- 1 5.
) :
Table[F[x,x2,xn],{x, xmin,xmax, step}, {x2,},{xn,}] n- ,
F.
Range[xmin,xmax,step]- xmin xmax step.
) : m[[2]]; M[[1,2]]; n[[1,2]]. M[[1]],
M 1- {a11,a12}.
) : Append[m, elem]; Prepend[m, elem]; Insert[m,
elem,pos];
m elem , pos.
Delete[m,pos] pos.
Take[m,{nmin,nmax}] m nmin nmax.
.
ij 1 0 0 yz
) : Dimensions[m];
j
z
) : DiagonalMatrix[{1,2,3}] jjj 0 2 0 zzz;
IdentityMatrix[n] nxn . Transpose[M]- k 0 0 3 {
M . Inverse[M]
. Det[M]- . Tr[M]- .
) : Dot[M1,M2], M1. M2
) Eigenvectors[d], Eigenvalues[d], Eigensystem[d]-
d.x=mx (m-,
m--).
LinearSolve[d, y]- d.x=y.
) : : MatrixForm[M]
( M// MatrixForm); TableForm[M] ( M// TableForm).

III.

1)
Simplify[expr] FullSimplify[expr] expr
Expand[expr] expr.
Collect[expr, {x1,x2..}] ,
x1,x2.
TrigExpand[expr] TrigReduce[expr] , Expand Collect
.
TrigToExp[expr] expr -
ExpToTrig[expr] , TrigToExp[expr].
2)
ReplaceAll[F,{x->expr1,y->expr2}]-
F x expr1 y expr2 .... :
F/.{x->expr1,y->expr2}.

ReplaceRepeated[F,{x->expr1,y->expr2}]
ReplaceAll , F . :
F//.{x->expr1,y->expr2}.

IV., ,

D[f[x], {x,n}]- n- f(x): n f HxL


Derivative[n1,n2,n3][f][a,b,c]- n1+ n2+ n3 f
xn
f(x1,x2,x3) {a,b,c}.
n1
n2
n3
x1 x2 x
Integrate[f[x],x]
- f(x).
x2
f
H
x
L

x
Integrate[f[x],{x,x1,x2}] x1
x2
NIntegrate[f[x],{x,x1,p1,p2,x2}] x1 f H x L x ,
imax
; p1,p2- f(x).
Sum[f[i], {i, imin, imax}] NSum[f[i], {i, imin, imax}] f HiL
i=imin
.
imax
Product[F[i], {i, imin, imax}] NProduct[F[i], {i, imin, imax}] . - F HiL
i=imin
.

V.
Solve[{eqn1,eqn2,}, {var1,var2,}] - -
eqn1,eqn2, var1,var2, eqn
leftside = = rightside.
: Solve[X^2+2X==0,X] : {{X-2},{X0}}.
NSolve[{eqn1,eqn2,}, {var1,var2,}] , Solve, .
: NSolve[X^2+2X==0,X] : {{X-2.},{X0.}}.
DSolve[{eqn1,eqn2,}, {F1[var1],F2[var2],}{var1,var2,}]
- - eqn1,eqn2, F1[var1],F2[var2],
var1,var2, eqn leftside==rightside.
, 1
( C1,C2 C[1],C[2]).
NDSolve[{eqn1,eqn2,}, {F1[var1],F2[var2],}{var1,var2,}] ,
DSolve, . ,
, eqn
() .

VI. ()

In[1]:=

Plot@8Sin@xD, Cos@xD<, 8x, 0, <,


In[26]:=
PlotStyle 88Hue@0D, Thickness@0.1D<,
8RGBColor@0, 1, 0D, Thickness@0.01D,
Dashing@80.05, 0.025<D<<D
In[32]:=
1

0.5

0.5

1.5

2.5

p = Plot3D@Sin@xD Cos@yD, 8x, 0, <, 8y, 0, <D;


p1 = ContourPlot@Sin@xD Cos@yD, 8x, 0, <, 8y, 0, <D;
p2 = DensityPlot@Sin@xD Cos@yD, 8x, 0, <, 8y, 0, <D;
Show@GraphicsArray@88Show@p, Mesh FalseD, Show@p,
Mesh True, Shading False, ViewPoint 80, 1, 1<,
BoxRatios 8200, 200, 100<D<, 8p1, p2<<DD

-0.5

ParametricPlotA8Sin@tD, Cos@tD<, 9t, 0, 3


-1

In[2]:=

0.5

-1

-0.5

0.5

-0.5

-1

0
1

VI:

1
0.5
-0.50
-1
0

=E

2
3
2
1

1
2

30

3
2.5
2
1.5
1
0.5
0
0 0.5 1 1.5 2 2.5 3

3
1
0.5
0
-0.5
-13

3
2.5
2
1.5
1
0.5
0
0 0.5 1 1.5 2 2.5 3

1) Evaluate
Mathematica, ,
, .

. Evaluate .
Plot[Evaluate[Table[BesselJ[n, x], {n, 1, 4}]], {x, 0, 10}]
2) , F ,
.
F,
Re[F], Im[F] Abs[F].
3)
ListPlot[{{x1,y1},{x2,y2},}],
ListPlot3D[{{z11,z12,..},{z21,z22,..},..}],
ListDensityPlot[
{{z11,z12,..}, {z21,z22,..},..}], ListContourPlot[{{z11,z12,..},{z21,z22,..},..}], yi
xi .

VII.
Eliminate[{eqn1,eqn2,}, {var1,var2,}] - var1,var2,
eqn1,eqn2,.
FindRoot[{eqn1,eqn2,},, {{var1,value1},{var2,value2}}] , var1=value1, var2=value2,, value1, value2, .

VIII.
Min[list] , Max[list]
list.
FindMinimum[F[x,y,],{x,x0},{y,y0},]
F[x,y,] x=x0,y=y0,, x0, y0, - .
: ConstrainedMin ,
,
. Mathematica 5
Minimize,Maximize,NMinimize,NMaximize.

IX.
1) :
:
) Put[expr1,expr2,expr3, "file.ext"] ( expr>>filename);
, file.ext expr1,expr2.
) PutAppend[expr1,expr2,expr3, "file.ext"] (
expr1>>>filename); Save[filename,exr2,expr3,] expr1,expr2
file.ext ( ).
:
In[1]:=

a@b_, c_D = 2 b c; M = 81, 2<; M >> "G:\1.dat"; a >>> "G:\1.dat"; Save@"G:\2.dat", M, aD;

G:\1.dat

G:\2.dat

{1, 2}
a

M = {1, 2}
a[b_, c_] = 2*b*c

:
) expr=Get["file.ext"] ( expr=<<filename)-

) ReadList["file.ext",{type1,type2,},n]
. ,{type1,type2,} n,
n , .
2) Export Import
Export["file.ext", expr] - expr file.ext ,
ext.
Export["file.ext ", expr, "format"] - expr file.ext "format".

expr =Import["file.ext"] - expr file.ext,


ext.
expr =Import["file.ext "format"] - expr file.ext,
"format".
"format"- ,
Mathematica - , , .
: In[28]:= P = Plot@Sin@xD, 8x, 0, 6<D; Export@"G:\1.jpg", PD
jpg-.
3) ToString ToExpession
ToString[expr] , expr;
ToExpession[text] ;
:
Dcm=3.
data>>"G:\MyFile[Dcm="<>ToString[Dcm]<>"].dat";
data MyFile[Dcm=3].dat ,
ToExpression["data1=<<G:\MyFile[Dcm="<>ToString[Dcm]<>"].dat"
];

data1 , .

X.
1) Module.
Module[{var1, var2,},expr1; expr2;. ;exprn]
expr1; expr2;, var1, var2, , ..
expr1; expr2;. ;exprn;
. exprn ;, Module
exprn, , .
In[29]:=
a = 1; b = 2; Module@8a<, a = b + 1; b = a;D ; 8a, b<
:
( b ,
Out[29]= 81, 3<
a )

2) Do.
In[2]:= z = 1; Do@z = F@zD, 85<D ; z
Do[expr, {imax}] expr imax . :Out[2]= F HF HF HF HF H1LLLLL
Do[expr, {i, imin, imax, step}] expr i,
imin imax step ( step ,
k = 1; z = 80, 0, 0, 0, 0<; Do@z@@kDD = i; k++, 8i, 2, 3, 0.3<D ; z
1).In[12]:=
:
Out[12]= 82, 2.3, 2.6, 2.9, 0<
3) For
For[start, test, incr, body] - start, body incr
, test. : ,
( ..3) )

In[1]:=
In[2]:=

MyFactorial@n_D := Module@8i<, For@i = 1; k = 1, i < n + 1, i ++, k = k iD; kD


MyFactorial@4D Out[2]= 24
start
test
incr body

4) .
If[condition, t] If[condition, t, f, u] condition ( a>b,a<b,
a = = b), (true), t,
(false), f, condition true false,
u.
:
If
Do For Return[expr] (expr
). Goto
5) . Goto[tag];
Label[tag];. : In[8]:= i = 3; Goto@3 + 2D; i = 2; Label@1 + 4D; i Out[1]= 3
6) -.
Which[condition1, expr1, condition2, expr2,] - expri,
conditioni.

Switch[expr, expr1, todo1, expr2, todo2, ]


expr expr1,expr2, true ,
todoi.