Wprowadzanie wyrazen w Mathematice

Transkrypt

Wprowadzanie wyrazen w Mathematice
1 z 52
Wprowadzanie wyrazen w Mathematice
Greckie litery
Greckie litery jako nazwy zmiennych
In[1]:=
Expand[(α + β)^3]
Out[1]=
In[2]:=
Expand[(\[Alpha] + \[Beta])^3]
Out[2]=
In[3]:=
Expand[(Rαβ + Ξ)^4]
Out[3]=
In[4]:=
Factor[πα^4 - 1]
Out[4]=
Uwaga: π oznacza Pi.
In[5]:=
N[π]
Out[5]=
Wyrazenia wielowymiarowe
Standardowy sposob wprowadzania wyrazen
In[6]:=
x^y
Out[6]=
Wyrazenie dwuwymiarowe wprowadzone bezposrednio...
In[7]:=
2006-11-12 14:07
2 z 52
Out[7]=
...przez wykorzystanie palety
...przez wykorzystanie kombinacji klawiszy
In[8]:=
x [CTRL]-[^] y
Out[8]=
In[9]:=
x [CTRL]-[^] y + z
Out[9]=
In[10]:=
x [CTRL]-[^] y [CTRL]-[_] + z
Out[10]=
In[11]:=
x [CTRL]-[_] y
Out[11]=
In[12]:=
x [CTRL]-[^] y [CTRL]-[%] z
Out[12]=
Wprowadzanie wzorow
2006-11-12 14:07
3 z 52
oznacza klawisz
.
In[13]:=
Sin[60°]
Out[13]=
In[14]:=
Sin[60 \[Degree]]
Out[14]=
In[15]:=
Sin[60 :deg:]
Out[15]=
In[16]:=
Out[16]=
In[17]:=
x/(x+1) /. x -> 3 + y
Out[17]=
In[18]:=
x/(x+1) /. x → 3 + y
Out[18]=
In[19]:=
x/(x+1) /. x :->: 3 + y
Out[19]=
In[20]:=
:int: f[x] :dd: x
Out[20]=
2006-11-12 14:07
4 z 52
In[21]:=
Out[21]=
In[22]:=
Integrate[Exp[-x^2], x]
Out[22]=
In[23]:=
Out[23]=
In[24]:=
D[x^n, x]
Out[24]=
In[25]:=
Out[25]=
In[26]:=
D[x^n, x, x, x]
Out[26]=
Tablice i macierze
In[27]:=
abc
123
Out[27]=
In[28]:=
Out[28]=
Obliczenia numeryczne
Arytmetyka
In[1]:=
2.3 + 5.63
Out[1]=
2006-11-12 14:07
5 z 52
In[2]:=
2.4 / 8.9 ^ 2
Out[2]=
In[3]:=
2 3 4
Out[3]=
In[4]:=
(3 + 4) ^ 2 - 2 (3 + 1)
Out[4]=
In[5]:=
2.4 ^ 45
Out[5]=
Obliczenia dokladne i przyblizone
In[6]:=
2 ^ 100
Out[6]=
In[7]:=
2 ^ 100 //N
Out[7]=
In[8]:=
1/3 + 2/7
Out[8]=
In[9]:=
1/3 + 2/7 //N
Out[9]=
In[10]:=
452/62
Out[10]=
In[11]:=
452.3/62
Out[11]=
2006-11-12 14:07
6 z 52
In[12]:=
452./62
Out[12]=
In[13]:=
1. + 452/62
Out[13]=
Funkcje matematyczne
In[14]:=
Log[8.4]
Out[14]=
In[15]:=
Sqrt[16]
Out[15]=
In[16]:=
Sqrt[2]
Out[16]=
In[17]:=
Sqrt[2] //N
Out[17]=
In[18]:=
Sqrt[2.]
Out[18]=
2006-11-12 14:07
7 z 52
In[19]:=
Pi ^ 2 //N
Out[19]=
In[20]:=
Sin[Pi/2]
Out[20]=
In[21]:=
Sin[20 Degree] //N
Out[21]=
In[22]:=
Log[E ^ 5]
Out[22]=
In[23]:=
Log[2, 256]
Out[23]=
Obliczenia o zadanej dokladnosci
In[24]:=
N[Pi]
Out[24]=
In[25]:=
N[Pi, 40]
Out[25]=
Liczby zespolone
In[26]:=
Sqrt[-4]
Out[26]=
In[27]:=
(4 + 3 I) / (2 - I)
Out[27]=
In[28]:=
2006-11-12 14:07
8 z 52
Exp[2 + 9 I] //N
Out[28]=
Techniki obliczeniowe
Wykorzystywanie poprzednich wynkiow
In[1]:=
77 ^ 2
Out[1]=
In[2]:=
% + 1
Out[2]=
In[3]:=
3 % + % ^ 2 + %%
Out[3]=
In[4]:=
%2 + %3
Out[4]=
Definiowanie zmiennych
In[5]:=
x = 5
Out[5]=
In[6]:=
x ^ 2
Out[6]=
In[7]:=
x = 7 + 4
Out[7]=
In[8]:=
2006-11-12 14:07
9 z 52
pi = N[Pi, 40]
Out[8]=
In[9]:=
pi
Out[9]=
In[10]:=
pi ^ 2
Out[10]=
Tworzenie list obiektow
In[11]:=
{3, 5, 1}
Out[11]=
In[12]:=
{3, 5, 1}^2 + 1
Out[12]=
In[13]:=
{6, 7, 8} - {3.5, 4, 2.5}
Out[13]=
In[14]:=
Exp[ % ] // N
Out[14]=
In[15]:=
v = {2, 4, 3.1}
Out[15]=
In[16]:=
v / (v - 1)
Out[16]=
Operowanie elementami list
In[17]:=
{5, 8, 6, 9}[[2]]
2006-11-12 14:07
10 z 52
Out[17]=
In[18]:=
{5, 8, 6, 9}[[ {3, 1, 3, 2, 4} ]]
Out[18]=
In[19]:=
v = {2, 4, 7}
Out[19]=
In[20]:=
v[[ 2 ]]
Out[20]=
In[21]:=
v = {4, -1, 8, 7}
Out[21]=
In[22]:=
v[[3]] = 0
Out[22]=
In[23]:=
v
Out[23]=
Cztery rodzaje nawiasow w Mathematice
Sekwencje operacji
In[24]:=
x = 4; y = 6; z = y + 6
Out[24]=
2006-11-12 14:07
11 z 52
In[25]:=
x = 67 - 5 ;
In[26]:=
%
Out[26]=
Praca z Mathematica
System pomocy w Mathematice
In[1]:=
?Log
Log[z] gives the natural logarithm of z (logarithm to base e). Log[b, z] gives the logarithm to base b.
In[2]:=
??Log
Log[z] gives the natural logarithm of z (logarithm to base e). Log[b, z] gives the logarithm to base b.
Attributes[Log] = {Listable, NumericFunction, Protected}
In[3]:=
2006-11-12 14:07
12 z 52
?Lo*
Locked
Log
LogGamma
LogicalExpand
LogIntegral
LongForm
Loopback
LowerCaseQ
In[4]:=
?:=
lhs := rhs assigns rhs to be the delayed value of lhs. rhs is maintained in an unevaluated form. When lhs appears, it is replaced by rhs, evaluated
afresh each time.
Pakiety Mathematici
In[5]:=
<< DiscreteMath`CombinatorialFunctions`
In[6]:=
Subfactorial[10]
Out[6]=
Ostrzezenia i komunikaty w Mathematice
In[7]:=
Sqrt[4, 5]
Sqrt::argx: Sqrt called with 2 arguments; 1 argument is expected.
Out[7]=
In[8]:=
Off[Sqrt::argx]
In[9]:=
Sqrt[4, 5]
Out[9]=
In[10]:=
On[Sqrt::argx]
Przerywanie obliczen w Mathematice
2006-11-12 14:07
13 z 52
Obliczenia algebraiczne
Obliczenia symboliczne
In[1]:=
-1 + 2x + x^3
Out[1]=
In[2]:=
x^2 + x - 4 x^2
Out[2]=
In[3]:=
x y + 2 x^2 y + y^2 x^2 - 2 y x
Out[3]=
In[4]:=
(x + 2y + 1)(x - 2)^2
Out[4]=
In[5]:=
Expand[%]
Out[5]=
In[6]:=
Factor[%]
Out[6]=
In[7]:=
Sqrt[2]/9801 (4n)! (1103 + 26390 n) / (n!^4 396^(4n))
Out[7]=
In[8]:=
Sqrt[1 + x]^4
Out[8]=
In[9]:=
Log[1 + Cos[x]]
Out[9]=
Podstawowa zasada Mathematici.
2006-11-12 14:07
14 z 52
Podstawianie wartosci pod symbole
In[10]:=
1 + 2x /. x -> 3
Out[10]=
In[11]:=
1 + x + x^2 /. x -> 2 - y
Out[11]=
In[12]:=
x -> 3 + y
Out[12]=
In[13]:=
x^2 - 9
/.
%
Out[13]=
In[14]:=
(x + y) (x - y)^2 /. {x -> 3, y -> 1 - a}
Out[14]=
In[15]:=
x = 3
Out[15]=
In[16]:=
x^2 - 1
Out[16]=
In[17]:=
x = 1 + a
Out[17]=
In[18]:=
x^2 - 1
Out[18]=
In[19]:=
x + 5 - 2x
Out[19]=
2006-11-12 14:07
15 z 52
In[20]:=
x =.
In[21]:=
x + 5 - 2x
Out[21]=
In[22]:=
t = 1 + x^2
Out[22]=
In[23]:=
t /. x -> 2
Out[23]=
In[24]:=
t /. x -> 5a
Out[24]=
In[25]:=
t /. x -> Pi //N
Out[25]=
Przeksztalcanie i upraszczanie wyrazen algebraicznych
In[26]:=
Expand[ (1 + x)^2 ]
Out[36]=
In[27]:=
Factor[ % ]
Out[27]=
In[28]:=
Factor[ x^10 - 1 ]
Out[28]=
In[29]:=
Expand[ % ]
Out[29]=
2006-11-12 14:07
16 z 52
In[30]:=
Simplify[x^2 + 2x + 1]
Out[30]=
In[31]:=
Simplify[x^10 - 1]
Out[31]=
In[32]:=
Integrate[1/(x^4-1), x]
Out[32]=
In[33]:=
D[%, x]
Out[33]=
In[34]:=
Simplify[%]
Out[34]=
In[35]:=
Simplify[Gamma[x] Gamma[1 - x]]
Out[35]=
In[36]:=
FullSimplify[Gamma[x] Gamma[1 - x]]
Out[36]=
Inne funkcje: ExpandAll[], Together[], Apart[], Cancel[], Collect[], FactorTerms[], TrigExpand[],
ComplexExpand[], PowerExpand[], TrigReduce[], TrigToExp[], ExpToTrig[]
Uzyskiwanie fragmentow wyrazen algebraicznych
In[37]:=
e = Expand[(1 + 3x + 4y^2)^2]
Out[37]=
In[38]:=
Coefficient[e, x]
Out[38]=
In[39]:=
Exponent[e, y]
Out[39]=
2006-11-12 14:07
17 z 52
In[40]:=
Part[e, 4]
Out[40]=
In[41]:=
r = (1 + x)/(2 (2 - y))
Out[41]=
In[42]:=
Denominator[%]
Out[42]=
Wyswietlanie wynikow obliczen
In[43]:=
Expand[(x + 5 y + 10)^8] ;
In[44]:=
% //Short
Out[44]//Short=
In[45]:=
Short[%, 3]
Out[45]//Short=
In[46]:=
Length[%]
Out[46]=
Matematyka symboliczna
Operacje podstawowe
2006-11-12 14:07
18 z 52
Rozniczkowanie
In[1]:=
D[ x^n, x ]
Out[1]=
In[2]:=
D[ ArcTan[x], x ]
Out[2]=
In[3]:=
D[ x^n, {x, 3} ]
Out[3]=
In[4]:=
Dt[ x^n, x ]
Out[4]=
In[5]:=
Dt[ x^n ]
Out[5]=
In[6]:=
D[ f[x], x ]
Out[6]=
In[7]:=
D[ 2 x f[x^2], x ]
Out[7]=
Calkowanie
2006-11-12 14:07
19 z 52
In[8]:=
Integrate[x^n, x]
Out[8]=
In[9]:=
Integrate[1/(x^4 - a^4), x]
Out[9]=
In[10]:=
Integrate[ x^x, x ]
Out[10]=
In[11]:=
Integrate[ Log[x], {x, a, b} ]
Out[11]=
In[12]:=
Integrate[Exp[-x^2], {x, 0, Infinity}]
Out[12]=
In[13]:=
Integrate[ x^x, {x, 0, 1} ]
Out[13]=
In[14]:=
N[ % ]
Out[14]=
In[15]:=
Integrate[ x^2 + y^2, {x, 0, 1}, {y, 0, x} ]
Out[15]=
Sumy i iloczyny
In[16]:=
2006-11-12 14:07
20 z 52
Sum[x^i/i, {i, 1, 7}]
Out[16]=
In[17]:=
Sum[x^i/i, {i, 1, 5, 2}]
Out[17]=
In[18]:=
Product[x + i, {i, 1, 4}]
Out[18]=
In[19]:=
Sum[1/i^4, {i, 1, Infinity}]
Out[19]=
In[20]:=
Sum[1/(i^4 + 2), {i, 1, Infinity}]
Out[20]=
In[21]:=
Sum[1/(i! + (2i)!), {i, 1, Infinity}]
Out[21]=
In[22]:=
N[%]
Out[22]=
In[23]:=
Sum[x^i y^j, {i, 1, 3}, {j, 1, i}]
Out[23]=
Rownania
In[24]:=
2 + 2 == 4
Out[24]=
In[25]:=
2006-11-12 14:07
21 z 52
x = 4
Out[25]=
In[26]:=
x
Out[26]=
In[27]:=
x == 6
Out[27]=
In[28]:=
x =.
In[29]:=
x == 5
Out[29]=
In[30]:=
% /. x -> 4
Out[30]=
In[31]:=
x^2 + 2 x - 7 == 0
Out[31]=
In[32]:=
eqn = %
Out[32]=
In[33]:=
eqn
Out[33]=
Relacje i operacje logiczne
In[34]:=
10 < 7
Out[34]=
In[35]:=
3 != 2 != 3
Out[35]=
2006-11-12 14:07
22 z 52
In[36]:=
3 < 5 <= 6
Out[36]=
In[37]:=
Pi^E < E^Pi
Out[37]=
In[38]:=
7 > 4 && 2 != 3
Out[38]=
In[39]:=
(p || q) && !(r || s)
Out[39]=
In[40]:=
LogicalExpand[ % ]
Out[40]=
Rozwiazywanie rownan algebraicznych
In[41]:=
Solve[x^2 + 2x - 7 == 0, x]
Out[41]=
In[42]:=
N[ % ]
Out[42]=
In[43]:=
x /. %
Out[43]=
In[44]:=
x^2 + 3 x /. %%
Out[44]=
2006-11-12 14:07
23 z 52
Mathematica zawsze rozwiaze rownanie algebraiczne jesli jego stopien jest nizszy niz piec.
In[45]:=
Solve[x^4 - 5 x^2 - 3 == 0, x]
Out[45]=
In[46]:=
Solve[2 - 4 x + x^5 == 0, x]
Out[46]=
In[47]:=
N[ % ]
Out[47]=
In[48]:=
Solve[ Sin[x] == a, x ]
Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found.
Out[48]=
In[49]:=
Solve[ Cos[x] == x, x ]
Solve::tdep: The equations appear to involve transcendental functions of the variables in an essentially non-algebraic way.
Out[49]=
In[50]:=
FindRoot[ Cos[x] == x, {x, 1} ]
Out[50]=
Rozwiazywanie rownan rozniczkowych
In[51]:=
DSolve[ y'[x] == a y[x] + 1, y[x], x ]
Out[51]=
In[52]:=
DSolve[ {y'[x] == a y[x] + 1, y[0] == 0}, y[x], x ]
Out[52]=
In[53]:=
DSolve[ {x'[t] == y[t], y'[t] == x[t]},{x[t], y[t]}, t ]
Out[53]=
2006-11-12 14:07
24 z 52
In[54]:=
DSolve[ y'[x] == x + y[x], y, x ]
Out[54]=
In[55]:=
y''[x] + y[x]
/.
%
Out[55]=
Granice
In[56]:=
t = Sin[x]/x
Out[56]=
In[57]:=
t /. x->0
1
Power::infy: Infinite expression - encountered.
0
Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered.
Out[57]=
In[58]:=
t /. x->0.01
Out[58]=
In[59]:=
Limit[t, x->0]
Out[59]=
Matematyka numeryczna
Operacje podstawowe
Numeryczne sumowanie, mnozenie, calkowanie
2006-11-12 14:07
25 z 52
In[1]:=
NSum[1/i^3, {i, 1, Infinity}]
Out[1]=
In[2]:=
NIntegrate[1/Sqrt[x (1-x)], {x, 0, 1}]
Out[2]=
In[3]:=
NIntegrate[Exp[-x^2], {x, -Infinity, Infinity}]
Out[3]=
In[4]:=
NIntegrate[ Sin[x y], {x, 0, 1}, {y, 0, x} ]
Out[4]=
Numeryczne rozwiazywanie rownan algebraicznych
In[5]:=
NSolve[ x^5 + x + 1 == 0, x ]
Out[5]=
In[6]:=
NSolve[{x + y == 2, x - 3 y + z == 3, x - y + z == 0},
{x, y, z}]
Out[6]=
In[7]:=
FindRoot[ 3 Cos[x] == Log[x], {x, 1} ]
Out[7]=
In[8]:=
FindRoot[ 3 Cos[x] == Log[x], {x, 10} ]
Out[8]=
2006-11-12 14:07
26 z 52
Numeryczne rozwiazywanie rownan rozniczkowych
In[9]:=
NDSolve[{y'[x] == y[x], y[0] == 1}, y, {x, 0, 2}]
Out[9]=
In[10]:=
y[1.5] /. %
Out[10]=
In[11]:=
NDSolve[ {y'[x] == z[x], z'[x] == -y[x], y[0] == 0,
z[0] == 1}, {y, z}, {x, 0, Pi} ]
Out[11]=
In[12]:=
z[2] /. %
Out[12]=
In[13]:=
Plot[Evaluate[z[x] /. %3], {x, 0, Pi}]
Optymalizacja numeryczna
Zadanie programowania liniowego
In[14]:=
ConstrainedMin[x - y - z, {y + z < 3, x > 7},
2006-11-12 14:07
27 z 52
{x, y, z}]
Out[14]=
In[15]:=
FindMinimum[x Cos[x], {x, 1}]
Out[15]=
In[16]:=
FindMinimum[x Cos[x], {x, 10}]
Out[16]=
In[17]:=
FindMinimum[Sin[x y], {x, 2}, {y, 2}]
Out[17]=
Operowanie danymi numerycznymi
In[18]:=
data = Table[ Exp[x/5.] , {x, 7}]
Out[18]=
In[19]:=
Fit[data, {1, x, x^2}, x]
Out[19]=
In[20]:=
Fit[data, {1, x, x^3, x^5}, x]
Out[20]=
In[21]:=
data = Table[ {x, Exp[Sin[x]]} , {x, 0., 1., 0.2}]
Out[21]=
In[22]:=
Fit[%, {1, Sin[x], Sin[2x]}, x]
Out[22]=
Statystyka
In[23]:=
<<Statistics`DescriptiveStatistics`
In[24]:=
data = {4.3, 7.2, 8.4, 5.8, 9.2, 3.9}
Out[24]=
In[25]:=
2006-11-12 14:07
28 z 52
Mean[data]
Out[25]=
In[26]:=
Variance[data]
Out[26]=
In[27]:=
DispersionReport[data]
Out[27]=
Funkcje i programy
Definiowanie funkcji
In[1]:=
f[x_] := x^2
In[2]:=
f[a+1]
Out[2]=
In[3]:=
f[4]
Out[3]=
In[4]:=
f[3x + x^2]
Out[4]=
In[5]:=
Expand[f[(x+1+y)]]
Out[5]=
In[6]:=
?f
Global`f
f[x_] := x^2
In[7]:=
hump[x_, xmax_] := (x - xmax)^2 / xmax
In[8]:=
2 + hump[x, 3.5]
Out[8]=
In[9]:=
hump[x_, xmax_] := (x - xmax)^4
In[10]:=
2006-11-12 14:07
29 z 52
?hump
Global`hump
hump[x_, xmax_] := (x - xmax)^4
Funkcje jako procedury
In[11]:=
Expand[ Product[x + i, {i, 3}] ]
Out[11]=
In[12]:=
Expand[ Product[x + i, {i, 4}] ]
Out[12]=
In[13]:=
exprod[n_] := Expand[ Product[ x + i, {i, 1, n} ] ]
In[14]:=
exprod[5]
Out[14]=
In[15]:=
cex[n_, i_] := ( t = exprod[n]; Coefficient[t, x^i] )
In[16]:=
ncex[n_, i_] :=
Module[{u}, u = exprod[n]; Coefficient[u, x^i]]
In[17]:=
cex[5, 3]
Out[17]=
Petle
In[18]:=
Do[ Print[i!], {i, 5} ]
1
2
6
24
120
2006-11-12 14:07
30 z 52
In[19]:=
Table[ i!, {i, 5} ]
Out[19]=
In[20]:=
r = 1; Do[ r = 1/(1 + r), {100} ]; r
Out[20]=
Reguly przeksztalcania dla funkcji
In[21]:=
1 + f[x] + f[y] /. x -> 3
Out[21]=
In[22]:=
1 + f[x] + f[y] /. f[x] -> p
Out[22]=
In[23]:=
1 + f[x] + f[y] /. f[t_] -> t^2
Out[23]=
In[24]:=
f[a b] + f[c d] /. f[x_ y_] -> f[x] + f[y]
Out[24]=
In[25]:=
1 + x^2 + x^4 /. x^p_ -> f[p]
Out[25]=
Listy
Laczenie obiektow w listy
In[1]:=
{2, 3, 4}
Out[1]=
In[2]:=
x^% - 1
Out[2]=
In[3]:=
D[%, x]
Out[3]=
In[4]:=
% /. x -> 3
Out[4]=
2006-11-12 14:07
31 z 52
Wektory i macierze
In[5]:=
m = {{a, b}, {c, d}}
Out[5]=
In[6]:=
m[[1]]
Out[6]=
In[7]:=
m[[1,2]]
Out[7]=
In[8]:=
v = {x, y}
Out[8]=
In[9]:=
p v + q
Out[9]=
In[10]:=
v + {xp, yp} + {xpp, ypp}
Out[10]=
In[11]:=
{x, y} . {xp, yp}
Out[11]=
In[12]:=
m . v
Out[12]=
In[13]:=
m . m
Out[13]=
Funkcje do tworzenia wektorow
2006-11-12 14:07
32 z 52
Funkcje do tworzenia macierzy
In[14]:=
s = Table[i+j, {i, 3}, {j, 3}]
Out[14]=
In[15]:=
MatrixForm[s]
Out[15]//MatrixForm=
In[16]:=
m
Out[16]=
In[17]:=
Det[m]
Out[17]=
2006-11-12 14:07
33 z 52
In[18]:=
Inverse[m]
Out[18]=
In[19]:=
r = Table[i+j+1, {i, 3}, {j, 3}]
Out[19]=
In[20]:=
Eigenvalues[r]
Out[20]=
Operowanie elementami list
In[21]:=
t = {a,b,c,d,e,f,g}
Out[21]=
In[22]:=
Take[t, 3]
Out[22]=
In[23]:=
Take[t, -3]
Out[23]=
In[24]:=
Take[t, {2, 5}]
Out[24]=
In[25]:=
Rest[t]
2006-11-12 14:07
34 z 52
Out[25]=
In[26]:=
Drop[t, 3]
Out[26]=
In[27]:=
Drop[t, {3, 3}]
Out[27]=
Testowanie i poszukiwanie elementow listy
In[28]:=
Position[{a, b, c, a, b}, a]
Out[28]=
In[29]:=
Count[{a, b, c, a, b}, a]
Out[29]=
In[30]:=
MemberQ[{a, b, c}, a]
Out[30]=
In[31]:=
MemberQ[{a, b, c}, d]
Out[31]=
In[32]:=
m = IdentityMatrix[3]
Out[32]=
In[33]:=
FreeQ[m, 0]
Out[33]=
In[34]:=
Position[m, 0]
Out[34]=
In[35]:=
Extract[m, %]
Out[35]=
2006-11-12 14:07
35 z 52
Dodawanie usuwanie i zamiana elementow list
In[36]:=
Prepend[{a, b, c}, x]
Out[36]=
In[37]:=
Append[{a, b, c}, x]
Out[37]=
In[38]:=
Insert[{a, b, c}, x, 2]
Out[38]=
In[39]:=
Insert[{a, b, c}, x, -2]
Out[39]=
In[40]:=
Delete[{a, b, c, d}, 3]
Out[40]=
In[41]:=
ReplacePart[{a, b, c, d}, x, 3]
Out[41]=
In[42]:=
ReplacePart[{a, b, c, d}, x, {{1}, {4}}]
Out[42]=
In[43]:=
IdentityMatrix[3]
Out[43]=
2006-11-12 14:07
36 z 52
In[44]:=
ReplacePart[%, x, {2, 2}]
Out[44]=
Laczenie list
In[45]:=
Join[{a, b, c}, {x, y}, {c, {d, e}, a}]
Out[45]=
In[46]:=
Union[{a, b, c}, {c, a, d}, {a, d}]
Out[46]=
Reorganizowanie list
In[47]:=
Sort[{b, a, c, a, b}]
Out[47]=
In[48]:=
Union[{b, a, c, a, b}]
Out[48]=
In[49]:=
Reverse[{a, b, c, d}]
Out[49]=
In[50]:=
RotateLeft[{a, b, c, d, e}, 2]
Out[50]=
In[51]:=
RotateLeft[{a, b, c, d, e}, -2]
Out[51]=
2006-11-12 14:07
37 z 52
Grupowanie elementow list
In[52]:=
t = {a, b, c, d, e, f, g}
Out[52]=
In[53]:=
Partition[t, 2]
Out[53]=
In[54]:=
Partition[t, 3]
Out[54]=
In[55]:=
Partition[t, 3, 1]
Out[55]=
In[56]:=
Split[{a, a, b, b, b, a, a, a, b}]
Out[56]=
Grafika i dzwiek
Podstawowe funkcje graficzne
In[1]:=
Plot[Sin[x], {x, 0, 2Pi}]
In[2]:=
Plot[Tan[x], {x, -3, 3}]
2006-11-12 14:07
38 z 52
In[3]:=
Plot[{Sin[x], Sin[2x], Sin[3x]}, {x, 0, 2Pi}]
Wizualizacja wynikow obliczen
In[4]:=
NDSolve[{y'[x] == Sin[y[x]], y[0] == 1}, y, {x, 0, 4}]
Out[4]=
In[5]:=
Plot[Evaluate[ y[x] /. % ], {x, 0, 4}]
Zmiana opcji wykresow
In[6]:=
Plot[Sin[x^2], {x, 0, 3}]
2006-11-12 14:07
39 z 52
In[7]:=
Plot[Sin[x^2], {x, 0, 3}, Frame->True]
In[8]:=
Plot[Sin[x^2], {x, 0, 3},
AxesLabel -> {"x value", "Sin[x^2]"} ]
In[9]:=
Plot[Sin[x^2], {x, 0, 3}, Frame -> True,
GridLines -> Automatic]
In[10]:=
Plot[Sin[x^2], {x, 0, 3}, AspectRatio -> 1]
Mozliwe wartosci opcji
Opcja PlotRange
In[11]:=
Plot[Sin[x^2], {x, 0, 3}, PlotRange -> {0, 1.2}]
2006-11-12 14:07
40 z 52
In[12]:=
Plot[Sin[1/x], {x, -1, 1}]
Manipulowanie wykresami
Przerysowywanie wykresow
In[13]:=
Plot[ChebyshevT[7, x], {x, -1, 1}]
In[14]:=
Show[%]
In[15]:=
Show[%, PlotRange -> {-1, 2}]
In[16]:=
Show[%, PlotLabel -> "A Chebyshev Polynomial"]
Laczenie wykresow
In[17]:=
gj0 = Plot[BesselJ[0, x], {x, 0, 10}]
2006-11-12 14:07
41 z 52
In[18]:=
gy1 = Plot[BesselY[1, x], {x, 1, 10}]
In[19]:=
gjy = Show[gj0, gy1]
In[20]:=
Show[GraphicsArray[{{gj0, gjy}, {gy1, gjy}}]]
In[21]:=
Show[%, Frame->True, FrameTicks->None]
In[22]:=
Show[ % /. (Ticks -> Automatic) -> (Ticks -> None) ]
Zmiana wartosci domyslnych opcji
In[23]:=
Options[Plot, PlotRange]
Out[23]=
2006-11-12 14:07
42 z 52
In[24]:=
SetOptions[Plot, PlotRange->All] ;
In[25]:=
Options[Plot, PlotRange]
Out[25]=
In[26]:=
g = Plot[SinIntegral[x], {x, 0, 20}]
In[27]:=
Options[g, PlotRange]
Out[27]=
In[28]:=
FullOptions[g, PlotRange]
Out[28]=
Wykresy trojwymiarowe
In[29]:=
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}]
In[30]:=
Show[%, PlotRange -> {-0.5, 0.5}]
2006-11-12 14:07
43 z 52
In[31]:=
Plot3D[10 Sin[x + Sin[y]], {x, -10, 10}, {y, -10, 10},
PlotPoints -> 40]
Zmiana punktu widzenia
In[32]:=
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}]
In[33]:=
Show[%, ViewPoint -> {0, -2, 0}]
In[34]:=
g = Plot3D[Exp[-(x^2+y^2)], {x, -2, 2}, {y, -2, 2}]
In[35]:=
Show[g, Mesh -> False]
In[36]:=
Show[g, Shading -> False]
2006-11-12 14:07
44 z 52
Wykresy na podstawie list danych
In[37]:=
t = Table[i^2, {i, 10}]
Out[37]=
In[38]:=
ListPlot[t]
In[39]:=
ListPlot[t, PlotJoined -> True]
In[40]:=
Table[{i^2, 4 i^2 + i^3}, {i, 10}]
Out[40]=
In[41]:=
ListPlot[%]
In[42]:=
2006-11-12 14:07
45 z 52
t3 = Table[Mod[x, y], {y, 20}, {x, 30}] ;
In[43]:=
ListPlot3D[t3]
In[44]:=
Show[%, ViewPoint -> {1.5, -0.5, 0}]
Wykresy parametryczne
In[45]:=
ParametricPlot[{Sin[t], Sin[2t]}, {t, 0, 2Pi}]
In[46]:=
ParametricPlot[{Sin[t], Cos[t]}, {t, 0, 2Pi}]
In[47]:=
Show[%, AspectRatio -> Automatic]
2006-11-12 14:07
46 z 52
In[48]:=
ParametricPlot3D[{Sin[t], Cos[t], t/3}, {t, 0, 15}]
In[49]:=
ParametricPlot3D[{t, u, Sin[t u]},
{t, 0, 3}, {u, 0, 3}]
In[50]:=
ParametricPlot3D[{u Sin[t], u Cos[t], t/3},
{t, 0, 15}, {u, -1, 1}]
In[51]:=
ParametricPlot3D[{Sin[t], Cos[t], u},
{t, 0, 2Pi}, {u, 0, 4}]
In[52]:=
ParametricPlot3D[
{Cos[t] (3 + Cos[u]), Sin[t] (3 + Cos[u]), Sin[u]},
{t, 0, 2Pi}, {u, 0, 2Pi}]
In[53]:=
ParametricPlot3D[
{Cos[t] Cos[u], Sin[t] Cos[u], Sin[u]},
{t, 0, 2Pi}, {u, -Pi/2, Pi/2}]
2006-11-12 14:07
47 z 52
Inne rodzaje wykresow
In[54]:=
<<Graphics`
In[55]:=
LogPlot[ Exp[-x] + 4 Exp[-2x], {x, 0, 6} ]
In[56]:=
p = Table[Prime[n], {n, 10}]
Out[56]=
In[57]:=
BarChart[p]
In[58]:=
PieChart[p]
2006-11-12 14:07
48 z 52
Animacja
In[59]:=
Table[ Plot3D[ BesselJ[0, Sqrt[x^2 + y^2] + t],
{x, -10, 10}, {y, -10, 10}, Axes -> False,
PlotRange -> {-0.5, 1.0},
DisplayFunction -> Identity ],
{t, 0, 8} ] // Short
Out[59]//Short=
In[60]:=
Show[ GraphicsArray[ Partition[%, 3] ] ]
Dzwiek
In[61]:=
Play[Sin[2Pi 440 t], {t, 0, 1}]
Out[61]=
-SoundIn[62]:=
Play[ Sin[700 t + 25 t Sin[350 t]], {t, 0, 4} ]
Out[62]=
-Sound-
2006-11-12 14:07
49 z 52
Operacje na plikach dyskowych
Wczytywanie i zapisywanie plikow Mathematici
In[1]:=
Expand[ (x + y)^3 ]
>> tmp
Zawartosc pliku
In[2]:=
!!tmp
x^3 + 3*x^2*y + 3*x*y^2 + y^3
Wczytanie pliku z wyliczeniem wyrazen znajdujacych sie w nim
In[3]:=
<<tmp
Out[3]=
In[4]:=
f[x_] := x^2 + c
In[5]:=
c = 17
Out[5]=
In[6]:=
Save["ftmp", f]
In[7]:=
!!ftmp
f[x_] := x^2 + c
c = 17
In[8]:=
<<ftmp;
2006-11-12 14:07
50 z 52
Wskazanie przy uzyciu pola Cell menu pozwala na wskazanie cel, ktore maja byc wyliczone automatycznie przy wczytaniu notebooka.
In[9]:=
Directory[ ]
Out[9]=
/users/sw
In[10]:=
SetDirectory["Examples"]
Out[10]=
/users/sw/Examples
In[11]:=
FileNames["Test*.m"]
Out[11]=
{Test1.m, Test2.m, TestFinal.m}
In[12]:=
FindList["index", "Laplace"]
Out[12]=
Wczytywanie plikow danych
In[13]:=
!!rand.dat
3.4
4.5
6.4
-5.7E-2 8.4E+2
-7.8E-2 1.9E+3
-0.1
4.7E+4
In[14]:=
ReadList["rand.dat", Number]
Out[14]=
In[15]:=
2006-11-12 14:07
51 z 52
ReadList["rand.dat", Number, RecordLists -> True]
Out[15]=
Generowanie wyrazen w formacie Fortranu i C
In[16]:=
Expand[(1 + x + y)^2]
Out[16]=
In[17]:=
FortranForm[%]
Out[17]//FortranForm=
In[18]:=
CForm[%]
Out[18]//CForm=
Makra obiektow takich jak funkcja Power sa zdefiniowane w pliku naglowkowym C mdefs.h dostarczanym wraz z Mathematica.
Eksportowanie grafiki
In[19]:=
Plot[Sin[x] + Sin[Sqrt[2] x], {x, 0, 10}]
In[20]:=
Display["sinplot.eps", %, "EPS"]
Out[20]=
In[21]:=
Display["!lpr", %, "EPS"]
Out[21]=
2006-11-12 14:07
52 z 52
Formaty nad kreska - wektorowe
Opcje funkcji Display.
Generowanie wyrazen w formacie TeX'a i HTML
In[22]:=
(x + y)^2 / Sqrt[x y]
Out[22]=
In[23]:=
TeXForm[%]
Out[23]//TeXForm=
2006-11-12 14:07