In[1]:= (* WSTĘP DO PAKIETU MATHEMATICA *) (* autorzy: Łukasz Płociniczak,Marek Teuerle*) (* Składnia: nazwy funkcji z wielkiej litery a argumenty w kwadratowych nawiasach. Wywołujemy wartość SHIFT+ENTER *) 3 + 5 E^Pi liczba Eulera Exp[1] funkcja eksponencjalna Sin[Pi / 4] Log[, 104] Prime[10] Out[1]= 8 Out[]= Out[3]= Out[4]= e π e 1 Out[5]= 10 Out[6]= 9 In[7]:= Out[7]= 9 Prime[10] In[8]:= (* Fajniejszy zapis: ułamek - CTRL+/, greckie litery - ESC literka ESC, potęga - CTRL+6, pierwiastek - CTRL+, mnożenie - SPACJA *) π e ϵ δ 9 4 5 Out[8]= e ϵ -δ 60 π α π α π 3 9
PM_Mathematica1_solved.nb 16 4 In[9]:= (* Zmienne i funkcje *) a = 5; b = 10; f[x_] := Tanh[x] + 5 tangens hiperboliczny f[a b] Out[1]= 5 + Tanh[50] In[13]:= (* Wartości numeryczne *) N[π] przybliżenie numeryczne 1. 3 N[e, 100] przybliżenie numeryczne 10 100 N e -158 przybliżenie numeryczne 1 + i 7 1 Re część 1rzeczywista - i Out[13]= 3.14159 Out[14]= 0.57735 Out[15]=.7188188459045353608747135664977574709369995957496696767740766303535475 94571381785516647 Out[16]= 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 Out[17]=.40698 10-69 Out[18]= Out[19]= 8-8 i 1 5
PM_Mathematica1_solved.nb 3 In[0]:= N[Pi, 1000] przybliżenie nume Out[0]= 3.1415965358979338466433837950884197169399375105809749445930781640686089 9868034853411706798148086513830664709384460955058317535940818481117450 841070193851105559644694895493038196448810975665933446184756483378678316 57101909145648566934603486104543664813393607604914173745870066063155881 748815090968954091715364367895903600113305305488046651384146951941511609 4330577036575959195309186117381936117931051185480744637996749567351885757 48917938183011949198336733644065664308601394946395473719070179860943707 705391717693176753846748184676694051300056817145635608778577134757789609 173637178714684409014953430146549585371050797968958935401995611190196 0864034418159813697747713099605187071134999999837978049951059731738160963185 95044594553469083064530853344685035619311881710100031378387588658753308 381406171776691473035985349048755468731159568638835378759375195778185778053 1716806613001978766111959091640199 In[30]:= (* Rysowanie *) Plot[x e -x, {x, 0, 10}] wykres 0.3 Out[30]= 0. 0.1 4 6 8 10
4 PM_Mathematica1_solved.nb In[31]:= Plot[Gamma[x], {x, -5, 5}] wykres 10 5 Out[31]= -4-4 -5-10 In[3]:= Plot3D x + y, {x, -1, 1}, {y, -1, 1} wykres trójwymiarowy Out[3]= In[33]:= Out[33]= ParametricPlot[{t Cos[t], Sin[t]}, {t, 0, π}] wykres parametryczny 1.0 0.5-4 6-0.5-1.0
PM_Mathematica1_solved.nb 5 In[34]:= ParametricPlot3D[{Cos[t], Sin[t], t}, {t, 0, 4 π}] trójwymiarowy wykres parametryczny Out[34]= In[35]:= Manipulate[ Plot[Sin[a x + b], {x, 0, 6}], {a, 1, 4}, {b, 0, 10}] zmieniaj wykres a b 1.0 Out[35]= 0.5 1 3 4 5 6-0.5-1.0
6 PM_Mathematica1_solved.nb In[36]:= Sin[a x] Manipulate Plot, {x, -10, 10}, PlotRange {-1, 1}, {a, 0, 1} zmieniaj wykres x zakres wykresu a 1. 1.0 Out[36]= 0.5-10 -5 5 10-0.5-1.0 (* Wektory i macierze *) In[37]:= w = {1,, 3} Out[37]= {1,, 3} In[38]:= v = {-1, 4, 5} Out[38]= {- 1, 4, 5} In[39]:= w.v Out[39]= In[40]:= Cross[w, v] Out[40]= {-, -8, 6} In[41]:= A = {{1,, 3}, {4, 5, 6}, {7, 8, 9}} Out[41]= {{1,, 3}, {4, 5, 6}, {7, 8, 9}}
PM_Mathematica1_solved.nb 7 In[4]:= A = {{1,, 3}, {4, 5, 6}, {7, 8, 9}} MatrixForm[A] postać macierzy B = {{1, 1, }, {5, 6, 7}, {-1,, 3}} Out[4]= {{1,, 3}, {4, 5, 6}, {7, 8, 9}} Out[43]//MatrixForm= 1 3 4 5 6 7 8 9 Out[44]= {{1, 1, }, {5, 6, 7}, {-1,, 3}} In[45]:= A.B // MatrixForm Out[45]//MatrixForm= 8 19 5 3 46 61 38 73 97 postać macierzy In[46]:= Eigenvalues[A] wartości własne macierzy Eigenvectors[ N[A]] wektory własne przybliże Out[46]= 3 5 + 33, 3 5-33, 0 Out[47]= {{- 0.31971, - 0.553, - 0.818673}, {- 0.78583, - 0.0867513, 0.6138}, {0.40848, - 0.816497, 0.40848}} In[48]:= Transpose[B] Inverse[B] macierz odwrotna Det[A] wyznacznik Inverse[A] macierz odwrotna Out[48]= {{1, 5, -1}, {1, 6, }, {, 7, 3}} Out[49]= 7, 1 14, - 5 14, - 11 7, 5 14, 3 14, 8 7, - 3 14, 1 14 Out[50]= 0 Inverse::sing : Matrix {{1,, 3}, {4, 5, 6}, {7, 8, 9}} is singular. Out[51]= Inverse[{{1,, 3}, {4, 5, 6}, {7, 8, 9}}]
8 PM_Mathematica1_solved.nb In[5]:= (* Inny sposób wpisywania macierzy: () i CTRL+ENTER - nowy wiersz, CTRL +, - nowa kolumna. TAB - przełączamy między polami *) 3 3 Out[5]= {{, 3}, {3, }} In[53]:= (* Listy *) Table n, {n, 1, 10} tabela Out[53]= {1, 4, 9, 16, 5, 36, 49, 64, 81, 100} In[54]:= Table[n m, {n, 1, 10}, {m, 1, 10}] // MatrixForm tabela Out[54]//MatrixForm= 1 3 4 5 6 7 8 9 10 4 6 8 10 1 14 16 18 0 3 6 9 1 15 18 1 4 7 30 4 8 1 16 0 4 8 3 36 40 5 10 15 0 5 30 35 40 45 50 6 1 18 4 30 36 4 48 54 60 7 14 1 8 35 4 49 56 63 70 8 16 4 3 40 48 56 64 7 80 9 18 7 36 45 54 63 7 81 90 10 0 30 40 50 60 70 80 90 100 postać macierzy In[55]:= Table[Prime[n], {n, 1, 100}] tabela Out[55]= {, 3, 5, 7, 11, 13, 17, 19, 3, 9, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 17, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 11, 3, 7, 9, 33, 39, 41, 51, 57, 63, 69, 71, 77, 81, 83, 93, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 41, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 51, 53, 541} In[56]:= ListPlot[ Table[Prime[n], {n, 1, 100}]] wykres da tabela 500 400 Out[56]= 300 00 100 0 40 60 80 100
PM_Mathematica1_solved.nb 9 In[57]:= ListPlot[ Table[ PrimePi[n], {n, 1, 1000}]] wykres da tabela ilość liczb pierwszych nie większych od 150 Out[57]= 100 50 00 400 600 800 1000 (* Rozwiązywanie równań lub układów *) In[58]:= Out[58]= Solve x -1, x rozwiąż równanie {{x -i}, {x i}} In[59]:= Solve x 3 - x + 3 0, x rozwiąż równanie Out[59]= x - 3 7-717 1/3 1 7-717 1/3 -, 3 /3 x 1 + i 3 1 7-717 1/3 1 - i 3 + 3 /3 /3 3 7-717 1/3, x 1 - i 3 1 7-717 1/3 1 + i 3 + 3 /3 /3 3 7-717 1/3 In[60]:= Out[60]= In[61]:= Solve[{x + y l, x - y k}, {x, y}] rozwiąż równanie x k + l, y 1 (-k + l) NSolve[x e x 1, x] rozwiąż numerycznie NSolve::ifun : Inverse functions are being used by NSolve, so some solutions may not be found; use Reduce for complete solution information. Out[61]= {{x 0.567143}}
10 PM_Mathematica1_solved.nb In[6]:= NSolve[ Tan[x] x, x] rozwiąż tangens NSolve::nsmet : This system cannot be solved with the methods available to NSolve. Out[6]= NSolve[Tan[x] x, x] In[63]:= FindRoot[ Tan[x] x, {x, 10}] znajdź pier tangens Plot[{ Tan[x], x}, {x, 0, 15}] wykres tangens Out[63]= {x 10.9041} 0 10 Out[64]= 4 6 8 10 1 14-10 (* Pochodne i całki *) In[65]:= Out[65]= D x, x x In[66]:= D[e x Sin[x], {x, 10}] Out[66]= 3 e x Cos[x] In[67]:= D[x x, {x, 4}] Out[67]= x -+x + - -1 + x + x x x-1+x + 3 x -1+x (1 + Log[x]) + x x (1 + Log[x]) 4 + x -1+x (1 + Log[x]) -1 + x -1 + x + Log[x] + x -1+x + Log[x] x x
PM_Mathematica1_solved.nb 11 In[68]:= f[x_] := x Cosh[x] cosinus hip f'[x] f''[x] f'''[x] f[x] Out[69]= Cosh[x] + x Sinh[x] Out[70]= x Cosh[x] + Sinh[x] Out[71]= 3 Cosh[x] + x Sinh[x] Out[7]= x Cosh[x] In[73]:= Out[73]= Integrate[f[x], x] całka - Cosh[x] + x Sinh[x] In[74]:= Out[74]= Integrate[x Sin[x], {x, 0, π}] całka - π (* Można też wpisywać ESC intt ESC lub ESC dintt ESC*) In[75]:= esin[x] dx Out[75]= esin[x] dx In[76]:= (* Szeregi też można tak wpisywać ESC ESC sumt ESC ESC *) 1 n=1 n 3 Out[76]= Zeta[3] In[77]:= (* Numeryczne całkowanie - wystarczy dodać N. Nieskończość wpisujemy ESC inf ESC *) przybliżenie numeryczne NIntegrate e -x, {x, 0, 1} numeryczne przybliżenie całki NIntegrate e -x, {x, 0, 100} numeryczne przybliżenie całki e -x dx 0 Out[77]= 0.74684 Out[78]= 0.8867 Out[79]= π
1 PM_Mathematica1_solved.nb In[80]:= π N przybliżenie numeryczne Out[80]= 0.8867 In[81]:= Out[81]= 0 Sin x dx π In[8]:= (* Liczby losowe *) Random[] Out[8]= 0.415 In[83]:= ListPlot[ Table[Random[], {n, 1, 100}]] wykres da tabela 1.0 0.8 0.6 Out[83]= 0.4 0. 0 40 60 80 100 In[84]:= ListPlot[ Table[Random[ Real, {3, 6}], {n, 1, 1000}]] wykres da tabela liczba rzeczywista 6.0 5.5 5.0 Out[84]= 4.5 4.0 3.5 3.0 00 400 600 800 1000 (* Rónania różniczkowe *)
PM_Mathematica1_solved.nb 13 In[85]:= DSolve[y'[x] y[x], y, x] Out[85]= {{y Function[{x}, e x C[1]]}} In[86]:= DSolve[{y'[x] + y[x] x, y[0] 1}, y, x] Out[86]= {{y Function[{x}, e -x ( - e x + e x x)]}} In[87]:= y0 = 0.01; y0' = 0.1; sol = NDSolve[{y''[x] Sin[y[x]], y[0] y0, y'[0] y0'}, y, {x, 0, 0}] rozwiąż numerycznie równanie różniczkowe Out[89]= y InterpolatingFunction Domain: {{0., 0.}} Output: scalar In[90]:= Plot[y[x] /. %, {x, 0, 0}] wykres 1 10 8 Out[90]= 6 4 5 10 15 0