Advertisement
morfeusz

PIERWSZE ZAJECIA PPS

Oct 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 29.22 KB | None | 0 0
  1. >> who
  2. >> a=12.99
  3.  
  4. a =
  5.  
  6.    12.9900
  7.  
  8. >> who
  9.  
  10. Your variables are:
  11.  
  12. a  
  13.  
  14. >> whos
  15.   Name      Size            Bytes  Class     Attributes
  16.  
  17.   a         1x1                 8  double              
  18.  
  19. >> A=[ 1 2 3; 4 5 6; 7 8 9]
  20.  
  21. A =
  22.  
  23.      1     2     3
  24.      4     5     6
  25.      7     8     9
  26.  
  27. >> who
  28.  
  29. Your variables are:
  30.  
  31. A  a  
  32.  
  33. >> whos
  34.   Name      Size            Bytes  Class     Attributes
  35.  
  36.   A         3x3                72  double              
  37.   a         1x1                 8  double              
  38.  
  39. >> B=[2 -1 3.5; -0.13 2.2; 3 0.5 34]
  40. Error using vertcat
  41. Dimensions of matrices being concatenated are not consistent.
  42.  
  43. >> B=[2 -1 3.5; -0.13 -0.3 2.2; 3 0.5 34]
  44.  
  45. B =
  46.  
  47.     2.0000   -1.0000    3.5000
  48.    -0.1300   -0.3000    2.2000
  49.     3.0000    0.5000   34.0000
  50.  
  51. >>
  52. >> whos
  53.   Name      Size            Bytes  Class     Attributes
  54.  
  55.   A         3x3                72  double              
  56.   B         3x3                72  double              
  57.   a         1x1                 8  double              
  58.  
  59. >> P=[]
  60.  
  61. P =
  62.  
  63.      []
  64.  
  65. >> whos
  66.   Name      Size            Bytes  Class     Attributes
  67.  
  68.   A         3x3                72  double              
  69.   B         3x3                72  double              
  70.   P         0x0                 0  double              
  71.   a         1x1                 8  double              
  72.  
  73. >> Suma = A + B
  74.  
  75. Suma =
  76.  
  77.     3.0000    1.0000    6.5000
  78.     3.8700    4.7000    8.2000
  79.    10.0000    8.5000   43.0000
  80.  
  81. >> Suma A+B ;
  82. Error: "Suma" was previously used as a variable, conflicting with its use here as the name of a function or command.
  83. See "How MATLAB Recognizes Command Syntax" in the MATLAB documentation for details.
  84.  
  85. >> Roz A-B
  86. Undefined function 'Roz' for input arguments of type 'char'.
  87.  
  88. >> Roz= A-B
  89.  
  90. Roz =
  91.  
  92.    -1.0000    3.0000   -0.5000
  93.     4.1300    5.3000    3.8000
  94.     4.0000    7.5000  -25.0000
  95.  
  96. >> A10=10*A
  97.  
  98. A10 =
  99.  
  100.     10    20    30
  101.     40    50    60
  102.     70    80    90
  103.  
  104. >> AP=5+A
  105.  
  106. AP =
  107.  
  108.      6     7     8
  109.      9    10    11
  110.     12    13    14
  111.  
  112. >> Mnoz=A*B
  113.  
  114. Mnoz =
  115.  
  116.    10.7400   -0.1000  109.9000
  117.    25.3500   -2.5000  229.0000
  118.    39.9600   -4.9000  348.1000
  119.  
  120. >> Dziel = A/B
  121.  
  122. Dziel =
  123.  
  124.    -0.4315   -4.5199    0.4251
  125.    -0.4857  -13.2421    1.0833
  126.    -0.5399  -21.9643    1.7415
  127.  
  128. >> Dziel1 = A*inv(B)
  129.  
  130. Dziel1 =
  131.  
  132.    -0.4315   -4.5199    0.4251
  133.    -0.4857  -13.2421    1.0833
  134.    -0.5399  -21.9643    1.7415
  135.  
  136. >> T=Dziel - Dziel1
  137.  
  138. T =
  139.  
  140.    1.0e-14 *
  141.  
  142.     0.0111   -0.0888   -0.0056
  143.     0.0111         0    0.0222
  144.     0.1221   -0.3553         0
  145.  
  146. >> Nowa=A.*B
  147.  
  148. Nowa =
  149.  
  150.     2.0000   -2.0000   10.5000
  151.    -0.5200   -1.5000   13.2000
  152.    21.0000    4.0000  306.0000
  153.  
  154. >> // powstajaca macierznowa
  155.  // powstajaca macierznowa
  156.  |
  157. Error: Unexpected MATLAB operator.
  158.  
  159. >> // skladniki iloczynu przechowywane sa w tej samej macierzy
  160.  // skladniki iloczynu przechowywane sa w tej samej macierzy
  161.  |
  162. Error: Unexpected MATLAB operator.
  163.  
  164. >> pierwszy wyrazA bedzie mial numer 1.1, zawsze peirwszy wiersz druga kolumna
  165. Undefined function 'pierwszy' for input arguments of type 'char'.
  166.  
  167. >> POT=A.^B
  168.  
  169. POT =
  170.  
  171.    1.0e+32 *
  172.  
  173.     0.0000    0.0000    0.0000
  174.     0.0000    0.0000    0.0000
  175.     0.0000    0.0000    2.7813
  176.  
  177. >> w podstawie a sa przechowywane wykladniki macierzy B
  178. Undefined function 'w' for input arguments of type 'char'.
  179.  
  180. >> teraz manipulacja blokami danych
  181. Undefined function 'teraz' for input arguments of type 'char'.
  182.  
  183. >> a
  184.  
  185. a =
  186.  
  187.    12.9900
  188.  
  189. >> A
  190.  
  191. A =
  192.  
  193.      1     2     3
  194.      4     5     6
  195.      7     8     9
  196.  
  197. >> B
  198.  
  199. B =
  200.  
  201.     2.0000   -1.0000    3.5000
  202.    -0.1300   -0.3000    2.2000
  203.     3.0000    0.5000   34.0000
  204.  
  205. >> chcemy utworzyc macierz 3x6 zeby A dolaczyc z prawej
  206. Undefined function 'chcemy' for input arguments of type 'char'.
  207.  
  208. >> laczymy teraz tablice
  209. Undefined function 'laczymy' for input arguments of type 'char'.
  210.  
  211. >> AB = [A, B]
  212.  
  213. AB =
  214.  
  215.     1.0000    2.0000    3.0000    2.0000   -1.0000    3.5000
  216.     4.0000    5.0000    6.0000   -0.1300   -0.3000    2.2000
  217.     7.0000    8.0000    9.0000    3.0000    0.5000   34.0000
  218.  
  219. >> utworz nowa macierz w pierwszym wierzu a i drugim wierszu b
  220. Undefined function 'utworz' for input arguments of type 'char'.
  221.  
  222. >> AB1 = [A; B]
  223.  
  224. AB1 =
  225.  
  226.     1.0000    2.0000    3.0000
  227.     4.0000    5.0000    6.0000
  228.     7.0000    8.0000    9.0000
  229.     2.0000   -1.0000    3.5000
  230.    -0.1300   -0.3000    2.2000
  231.     3.0000    0.5000   34.0000
  232.  
  233. >> whos
  234.   Name        Size            Bytes  Class     Attributes
  235.  
  236.   A           3x3                72  double              
  237.   A10         3x3                72  double              
  238.   AB          3x6               144  double              
  239.   AB1         6x3               144  double              
  240.   AP          3x3                72  double              
  241.   B           3x3                72  double              
  242.   Dziel       3x3                72  double              
  243.   Dziel1      3x3                72  double              
  244.   Mnoz        3x3                72  double              
  245.   Nowa        3x3                72  double              
  246.   P           0x0                 0  double              
  247.   POT         3x3                72  double              
  248.   Roz         3x3                72  double              
  249.   Suma        3x3                72  double              
  250.   T           3x3                72  double              
  251.   a           1x1                 8  double              
  252.  
  253. >> ABB = [AB, B, A]
  254.  
  255. ABB =
  256.  
  257.     1.0000    2.0000    3.0000    2.0000   -1.0000    3.5000    2.0000   -1.0000    3.5000    1.0000    2.0000    3.0000
  258.     4.0000    5.0000    6.0000   -0.1300   -0.3000    2.2000   -0.1300   -0.3000    2.2000    4.0000    5.0000    6.0000
  259.     7.0000    8.0000    9.0000    3.0000    0.5000   34.0000    3.0000    0.5000   34.0000    7.0000    8.0000    9.0000
  260.  
  261. >> whos
  262.   Name        Size            Bytes  Class     Attributes
  263.  
  264.   A           3x3                72  double              
  265.   A10         3x3                72  double              
  266.   AB          3x6               144  double              
  267.   AB1         6x3               144  double              
  268.   ABB         3x12              288  double              
  269.   AP          3x3                72  double              
  270.   B           3x3                72  double              
  271.   Dziel       3x3                72  double              
  272.   Dziel1      3x3                72  double              
  273.   Mnoz        3x3                72  double              
  274.   Nowa        3x3                72  double              
  275.   P           0x0                 0  double              
  276.   POT         3x3                72  double              
  277.   Roz         3x3                72  double              
  278.   Suma        3x3                72  double              
  279.   T           3x3                72  double              
  280.   a           1x1                 8  double              
  281.  
  282. >> size(ABB)
  283.  
  284. ans =
  285.  
  286.      3    12
  287.  
  288. >> polecenie wyzej to sprawdzenie wielkosci tablicy
  289. Undefined function 'polecenie' for input arguments of type 'char'.
  290.  
  291. >> AB2= [AB;B,B]
  292.  
  293. AB2 =
  294.  
  295.     1.0000    2.0000    3.0000    2.0000   -1.0000    3.5000
  296.     4.0000    5.0000    6.0000   -0.1300   -0.3000    2.2000
  297.     7.0000    8.0000    9.0000    3.0000    0.5000   34.0000
  298.     2.0000   -1.0000    3.5000    2.0000   -1.0000    3.5000
  299.    -0.1300   -0.3000    2.2000   -0.1300   -0.3000    2.2000
  300.     3.0000    0.5000   34.0000    3.0000    0.5000   34.0000
  301.  
  302. >> AB3 = [A,A;B]
  303. Error using vertcat
  304. Dimensions of matrices being concatenated are not consistent.
  305.  
  306. >> wyzej nie dziala bo niezgodne wymiary
  307. Undefined function 'wyzej' for input arguments of type 'char'.
  308.  
  309. >> dana=AB(2,3)
  310.  
  311. dana =
  312.  
  313.      6
  314.  
  315. >> 2*6+2
  316.  
  317. ans =
  318.  
  319.     14
  320.  
  321. >> teraz tworzy sie ans czyli answer, nazwa domyslna zmiennej nieprzypisanej zadnej zmiennej
  322. Undefined function 'teraz' for input arguments of type 'char'.
  323.  
  324. >> transponowanie macierzy
  325. Undefined function 'transponowanie' for input arguments of type 'char'.
  326.  
  327. >> AT=A'
  328.  
  329. AT =
  330.  
  331.      1     4     7
  332.      2     5     8
  333.      3     6     9
  334.  
  335. >> help clear
  336.  clear  Clear variables and functions from memory.
  337.     clear removes all variables from the workspace.
  338.     clear VARIABLES does the same thing.
  339.     clear GLOBAL removes all global variables.
  340.     clear FUNCTIONS removes all compiled MATLAB and MEX-functions.
  341.  
  342.     clear ALL removes all variables, globals, functions and MEX links.
  343.     clear ALL at the command prompt also clears the base import list.
  344.  
  345.     clear IMPORT clears the base import list.  It can only be issued at the
  346.     command prompt. It cannot be used in a function.
  347.  
  348.     clear CLASSES is the same as clear ALL except that class definitions
  349.     are also cleared. If any objects exist outside the workspace (say in
  350.     userdata or persistent in a locked program file) a warning will be
  351.     issued and the class definition will not be cleared. clear CLASSES must
  352.     be used if the number or names of fields in a class are changed.
  353.  
  354.     clear JAVA is the same as clear ALL except that java classes on the
  355.     dynamic java path (defined using JAVACLASSPATH) are also cleared.
  356.  
  357.     clear VAR1 VAR2 ... clears the variables specified. The wildcard
  358.     character '*' can be used to clear variables that match a pattern. For
  359.     instance, clear X* clears all the variables in the current workspace
  360.     that start with X.
  361.  
  362.     clear -REGEXP PAT1 PAT2 can be used to match all patterns using regular
  363.     expressions. This option only clears variables. For more information on
  364.     using regular expressions, type "doc regexp" at the command prompt.
  365.  
  366.     If X is global, clear X removes X from the current workspace, but
  367.     leaves it accessible to any functions declaring it global.
  368.     clear GLOBAL X completely removes the global variable X.
  369.     clear GLOBAL -REGEXP PAT removes global variables that match regular
  370.     expression patterns.
  371.     Note that to clear specific global variables, the GLOBAL option must
  372.     come first. Otherwise, all global variables will be cleared.
  373.  
  374.     clear FUN clears the function specified. If FUN has been locked by
  375.     MLOCK it will remain in memory. Use a partial path (see PARTIALPATH) to
  376.     distinguish between different overloaded versions of FUN.  For
  377.     instance, 'clear inline/display' clears only the INLINE method for
  378.     DISPLAY, leaving any other implementations in memory.
  379.  
  380.     clear ALL, clear FUN, or clear FUNCTIONS also have the side effect of
  381.     removing debugging breakpoints and reinitializing persistent variables
  382.     since the breakpoints for a function and persistent variables are
  383.     cleared whenever the program file changes or is cleared.
  384.  
  385.     Use the functional form of clear, such as clear('name'), when the
  386.     variable name or function name is stored in a string.
  387.  
  388.     Examples for pattern matching:
  389.         clear a*                % Clear variables starting with "a"
  390.         clear -regexp ^b\d{3}$  % Clear variables starting with "b" and
  391.                                 %    followed by 3 digits
  392.         clear -regexp \d        % Clear variables containing any digits
  393.  
  394.     See also clearvars, who, whos, mlock, munlock, persistent, import.
  395.  
  396.     Reference page in Help browser
  397.        doc clear
  398.  
  399. >> diag(A)
  400.  
  401. ans =
  402.  
  403.      1
  404.      5
  405.      9
  406.  
  407. >> czyli glowna przekatna
  408. Undefined function 'czyli' for input arguments of type 'char'.
  409.  
  410. >> diag(AB)
  411.  
  412. ans =
  413.  
  414.      1
  415.      5
  416.      9
  417.  
  418. >> det(A)
  419.  
  420. ans =
  421.  
  422.    6.6613e-16
  423.  
  424. >> wyznacznik macierzy, proste
  425. Undefined function 'wyznacznik' for input arguments of type 'char'.
  426.  
  427. >> poznajemy operator zakresu, czyli range operator
  428. Undefined function 'poznajemy' for input arguments of type 'char'.
  429.  
  430. >> kiedy chcemy skopiowac fragment jakiejs wiekszej tablicy
  431. Undefined function 'kiedy' for input arguments of type 'char'.
  432.  
  433. >> AB2=[ A A A; B B B]
  434.  
  435. AB2 =
  436.  
  437.     1.0000    2.0000    3.0000    1.0000    2.0000    3.0000    1.0000    2.0000    3.0000
  438.     4.0000    5.0000    6.0000    4.0000    5.0000    6.0000    4.0000    5.0000    6.0000
  439.     7.0000    8.0000    9.0000    7.0000    8.0000    9.0000    7.0000    8.0000    9.0000
  440.     2.0000   -1.0000    3.5000    2.0000   -1.0000    3.5000    2.0000   -1.0000    3.5000
  441.    -0.1300   -0.3000    2.2000   -0.1300   -0.3000    2.2000   -0.1300   -0.3000    2.2000
  442.     3.0000    0.5000   34.0000    3.0000    0.5000   34.0000    3.0000    0.5000   34.0000
  443.  
  444. >> size(AB2)
  445.  
  446. ans =
  447.  
  448.      6     9
  449.  
  450. >> Anowa = AB(2:5; 2:3)
  451.  Anowa = AB(2:5; 2:3)
  452.                |
  453. Error: Unbalanced or unexpected parenthesis or bracket.
  454.  
  455. >> Anowa = AB(2:5,2:3)
  456. Index exceeds matrix dimensions.
  457.  
  458. >> wiersz4 = AB2(4,1:9)
  459.  
  460. wiersz4 =
  461.  
  462.     2.0000   -1.0000    3.5000    2.0000   -1.0000    3.5000    2.0000   -1.0000    3.5000
  463.  
  464. >> wiersz41=AB2(4, :)
  465.  
  466. wiersz41 =
  467.  
  468.     2.0000   -1.0000    3.5000    2.0000   -1.0000    3.5000    2.0000   -1.0000    3.5000
  469.  
  470. >> kol2=AB@( : , 2)
  471.  kol2=AB@( : , 2)
  472.          |
  473. Error: Unbalanced or unexpected parenthesis or bracket.
  474.  
  475. >> kol2=AB2(:,2)
  476.  
  477. kol2 =
  478.  
  479.     2.0000
  480.     5.0000
  481.     8.0000
  482.    -1.0000
  483.    -0.3000
  484.     0.5000
  485.  
  486. >> kol2t=kol2'
  487.  
  488. kol2t =
  489.  
  490.     2.0000    5.0000    8.0000   -1.0000   -0.3000    0.5000
  491.  
  492. >> A
  493.  
  494. A =
  495.  
  496.      1     2     3
  497.      4     5     6
  498.      7     8     9
  499.  
  500. >> sum(A)
  501.  
  502. ans =
  503.  
  504.     12    15    18
  505.  
  506. >> sum(A')
  507.  
  508. ans =
  509.  
  510.      6    15    24
  511.  
  512. >> sum(A')'
  513.  
  514. ans =
  515.  
  516.      6
  517.     15
  518.     24
  519.  
  520. >> wektory - ciagi liczbowe
  521.  wektory - ciagi liczbowe
  522.                  |
  523. Error: Unexpected MATLAB expression.
  524.  
  525. >> operator zakresu to dwukropek
  526. Undefined function 'operator' for input arguments of type 'char'.
  527.  
  528. >> k=0:10
  529.  
  530. k =
  531.  
  532.      0     1     2     3     4     5     6     7     8     9    10
  533.  
  534. >> k1=2:0.1:3.2
  535.  
  536. k1 =
  537.  
  538.   Columns 1 through 12
  539.  
  540.     2.0000    2.1000    2.2000    2.3000    2.4000    2.5000    2.6000    2.7000    2.8000    2.9000    3.0000    3.1000
  541.  
  542.   Column 13
  543.  
  544.     3.2000
  545.  
  546. >> czyli zaczynamy od 2 z krokiem co 0.1 i do 3.2
  547. Undefined function 'czyli' for input arguments of type 'char'.
  548.  
  549. >> ciagx=2:5:49
  550.  
  551. ciagx =
  552.  
  553.      2     7    12    17    22    27    32    37    42    47
  554.  
  555. >> % (ogolnie: ciag = start :krok/przyrost: koncowa wartosc/koniec)
  556. >> cl=1:0.7:12
  557.  
  558. cl =
  559.  
  560.   Columns 1 through 12
  561.  
  562.     1.0000    1.7000    2.4000    3.1000    3.8000    4.5000    5.2000    5.9000    6.6000    7.3000    8.0000    8.7000
  563.  
  564.   Columns 13 through 16
  565.  
  566.     9.4000   10.1000   10.8000   11.5000
  567.  
  568. >> size(cl)
  569.  
  570. ans =
  571.  
  572.      1    16
  573.  
  574. >> r=size(cl)
  575.  
  576. r =
  577.  
  578.      1    16
  579.  
  580. >> size(r)
  581.  
  582. ans =
  583.  
  584.      1     2
  585.  
  586. >> w=r(1,1)
  587.  
  588. w =
  589.  
  590.      1
  591.  
  592. >> kol=r(1,2)
  593.  
  594. kol =
  595.  
  596.     16
  597.  
  598. >> [w,k]=size(cl)
  599.  
  600. w =
  601.  
  602.      1
  603.  
  604.  
  605. k =
  606.  
  607.     16
  608.  
  609. >> w
  610.  
  611. w =
  612.  
  613.      1
  614.  
  615. >> k
  616.  
  617. k =
  618.  
  619.     16
  620.  
  621. >> dl=length(cl)
  622.  
  623. dl =
  624.  
  625.     16
  626.  
  627. >> c2=1:-0.2:-1
  628.  
  629. c2 =
  630.  
  631.     1.0000    0.8000    0.6000    0.4000    0.2000         0   -0.2000   -0.4000   -0.6000   -0.8000   -1.0000
  632.  
  633. >> c3=-1:-0.2:1
  634.  
  635. c3 =
  636.  
  637.    Empty matrix: 1-by-0
  638.  
  639. >> k=0:20
  640.  
  641. k =
  642.  
  643.   Columns 1 through 20
  644.  
  645.      0     1     2     3     4     5     6     7     8     9    10    11    12    13    14    15    16    17    18    19
  646.  
  647.   Column 21
  648.  
  649.     20
  650.  
  651. >> kpol=0.5*k
  652.  
  653. kpol =
  654.  
  655.   Columns 1 through 12
  656.  
  657.          0    0.5000    1.0000    1.5000    2.0000    2.5000    3.0000    3.5000    4.0000    4.5000    5.0000    5.5000
  658.  
  659.   Columns 13 through 21
  660.  
  661.     6.0000    6.5000    7.0000    7.5000    8.0000    8.5000    9.0000    9.5000   10.0000
  662.  
  663. >> kk=5+k
  664.  
  665. kk =
  666.  
  667.   Columns 1 through 20
  668.  
  669.      5     6     7     8     9    10    11    12    13    14    15    16    17    18    19    20    21    22    23    24
  670.  
  671.   Column 21
  672.  
  673.     25
  674.  
  675. >> pi
  676.  
  677. ans =
  678.  
  679.     3.1416
  680.  
  681. >> i
  682.  
  683. ans =
  684.  
  685.    0.0000 + 1.0000i
  686.  
  687. >> j
  688.  
  689. ans =
  690.  
  691.    0.0000 + 1.0000i
  692.  
  693. >> %pi to taka predefiniowana stala, nie musimy dysponowac jej dokladna wartoscia
  694. >> e
  695. Undefined function or variable 'e'.
  696.  
  697. >> %kiedy wpisujemy "i" to jednostka urojona, podobnie dziala "j"
  698. >> %matlab dziala na liczbach rzeczywistych i zespolonych
  699. >> pi=50
  700.  
  701. pi =
  702.  
  703.     50
  704.  
  705. >> who
  706.  
  707. Your variables are:
  708.  
  709. A         AB2       B         Nowa      Suma      c2        dana      kk        kpol      wiersz4  
  710. A10       ABB       Dziel     P         T         c3        dl        kol       pi        wiersz41  
  711. AB        AP        Dziel1    POT       a         ciagx     k         kol2      r        
  712. AB1       AT        Mnoz      Roz       ans       cl        k1        kol2t     w        
  713.  
  714. >> %po takiej operacji zmienna zablokuje nam dostep do predefiniowanej liczby pi
  715. >> %jak odzyskac dostep do liczby pi do jej normalnej wartosci?
  716. >> %who maskuje dostep do predefinoiwanej jednostki, jezeli w komendzie, poleceniu pojawi sie nazwa zmiennej to wtedy matlab rozpoczyna przeszukiwanie i jesli jej nie nzajdzie szuka
  717. >> mx=max(A)
  718.  
  719. mx =
  720.  
  721.      7     8     9
  722.  
  723. >> mn=min(A)
  724.  
  725. mn =
  726.  
  727.      1     2     3
  728.  
  729. >> mmm=max(mx)  
  730.  
  731. mmm =
  732.  
  733.      9
  734.  
  735. >> mmm=max(max(A))
  736.  
  737. mmm =
  738.  
  739.      9
  740.  
  741. >> E=eye(4)
  742.  
  743. E =
  744.  
  745.      1     0     0     0
  746.      0     1     0     0
  747.      0     0     1     0
  748.      0     0     0     1
  749.  
  750. >> %macierz jednostkowa
  751. >> E1=eye(4,7)
  752.  
  753. E1 =
  754.  
  755.      1     0     0     0     0     0     0
  756.      0     1     0     0     0     0     0
  757.      0     0     1     0     0     0     0
  758.      0     0     0     1     0     0     0
  759.  
  760. >> E1=eye(6,3)
  761.  
  762. E1 =
  763.  
  764.      1     0     0
  765.      0     1     0
  766.      0     0     1
  767.      0     0     0
  768.      0     0     0
  769.      0     0     0
  770.  
  771. >> %magic robi ze wszystkie sumy wyrazow w wierszach i kolumnach sa jednakowe
  772. >> M=magic(6)
  773.  
  774. M =
  775.  
  776.     35     1     6    26    19    24
  777.      3    32     7    21    23    25
  778.     31     9     2    22    27    20
  779.      8    28    33    17    10    15
  780.     30     5    34    12    14    16
  781.      4    36    29    13    18    11
  782.  
  783. >> w1=sum(M)
  784.  
  785. w1 =
  786.  
  787.    111   111   111   111   111   111
  788.  
  789. >> %sumowanie wartosci w kolumnach
  790. >> w2=sum(M')
  791.  
  792. w2 =
  793.  
  794.    111   111   111   111   111   111
  795.  
  796. >> %sumowanie wartosci w wierszach
  797. >> J=ones(3,6)
  798.  
  799. J =
  800.  
  801.      1     1     1     1     1     1
  802.      1     1     1     1     1     1
  803.      1     1     1     1     1     1
  804.  
  805. >> Z=zeros(4,5)
  806.  
  807. Z =
  808.  
  809.      0     0     0     0     0
  810.      0     0     0     0     0
  811.      0     0     0     0     0
  812.      0     0     0     0     0
  813.  
  814. >> % stworzymy sobie kolejno wektor 4 zer a potem z 4 jedynek czy jakos tak
  815. >> Z=zeros(1,4)
  816.  
  817. Z =
  818.  
  819.      0     0     0     0
  820.  
  821. >> J=ones(1,4)
  822.  
  823. J =
  824.  
  825.      1     1     1     1
  826.  
  827. >> okres=[J,Z]
  828.  
  829. okres =
  830.  
  831.      1     1     1     1     0     0     0     0
  832.  
  833. >> syg=[okres, okres, okres, okres, okres]
  834.  
  835. syg =
  836.  
  837.   Columns 1 through 20
  838.  
  839.      1     1     1     1     0     0     0     0     1     1     1     1     0     0     0     0     1     1     1     1
  840.  
  841.   Columns 21 through 40
  842.  
  843.      0     0     0     0     1     1     1     1     0     0     0     0     1     1     1     1     0     0     0     0
  844.  
  845. >> length(syg)
  846.  
  847. ans =
  848.  
  849.     40
  850.  
  851. >> %uzywanie petli - macierz pusta
  852. >> sygnal =[]
  853.  
  854. sygnal =
  855.  
  856.      []
  857.  
  858. >> for i=1:10
  859. sygnal=[sygnal;okres]
  860. end
  861.  
  862. sygnal =
  863.  
  864.      1     1     1     1     0     0     0     0
  865.  
  866.  
  867. sygnal =
  868.  
  869.      1     1     1     1     0     0     0     0
  870.      1     1     1     1     0     0     0     0
  871.  
  872.  
  873. sygnal =
  874.  
  875.      1     1     1     1     0     0     0     0
  876.      1     1     1     1     0     0     0     0
  877.      1     1     1     1     0     0     0     0
  878.  
  879.  
  880. sygnal =
  881.  
  882.      1     1     1     1     0     0     0     0
  883.      1     1     1     1     0     0     0     0
  884.      1     1     1     1     0     0     0     0
  885.      1     1     1     1     0     0     0     0
  886.  
  887.  
  888. sygnal =
  889.  
  890.      1     1     1     1     0     0     0     0
  891.      1     1     1     1     0     0     0     0
  892.      1     1     1     1     0     0     0     0
  893.      1     1     1     1     0     0     0     0
  894.      1     1     1     1     0     0     0     0
  895.  
  896.  
  897. sygnal =
  898.  
  899.      1     1     1     1     0     0     0     0
  900.      1     1     1     1     0     0     0     0
  901.      1     1     1     1     0     0     0     0
  902.      1     1     1     1     0     0     0     0
  903.      1     1     1     1     0     0     0     0
  904.      1     1     1     1     0     0     0     0
  905.  
  906.  
  907. sygnal =
  908.  
  909.      1     1     1     1     0     0     0     0
  910.      1     1     1     1     0     0     0     0
  911.      1     1     1     1     0     0     0     0
  912.      1     1     1     1     0     0     0     0
  913.      1     1     1     1     0     0     0     0
  914.      1     1     1     1     0     0     0     0
  915.      1     1     1     1     0     0     0     0
  916.  
  917.  
  918. sygnal =
  919.  
  920.      1     1     1     1     0     0     0     0
  921.      1     1     1     1     0     0     0     0
  922.      1     1     1     1     0     0     0     0
  923.      1     1     1     1     0     0     0     0
  924.      1     1     1     1     0     0     0     0
  925.      1     1     1     1     0     0     0     0
  926.      1     1     1     1     0     0     0     0
  927.      1     1     1     1     0     0     0     0
  928.  
  929.  
  930. sygnal =
  931.  
  932.      1     1     1     1     0     0     0     0
  933.      1     1     1     1     0     0     0     0
  934.      1     1     1     1     0     0     0     0
  935.      1     1     1     1     0     0     0     0
  936.      1     1     1     1     0     0     0     0
  937.      1     1     1     1     0     0     0     0
  938.      1     1     1     1     0     0     0     0
  939.      1     1     1     1     0     0     0     0
  940.      1     1     1     1     0     0     0     0
  941.  
  942.  
  943. sygnal =
  944.  
  945.      1     1     1     1     0     0     0     0
  946.      1     1     1     1     0     0     0     0
  947.      1     1     1     1     0     0     0     0
  948.      1     1     1     1     0     0     0     0
  949.      1     1     1     1     0     0     0     0
  950.      1     1     1     1     0     0     0     0
  951.      1     1     1     1     0     0     0     0
  952.      1     1     1     1     0     0     0     0
  953.      1     1     1     1     0     0     0     0
  954.      1     1     1     1     0     0     0     0
  955.  
  956. >> help randn
  957.  randn Normally distributed pseudorandom numbers.
  958.     R = randn(N) returns an N-by-N matrix containing pseudorandom values drawn
  959.     from the standard normal distribution.  randn(M,N) or randn([M,N]) returns
  960.     an M-by-N matrix. randn(M,N,P,...) or randn([M,N,P,...]) returns an
  961.     M-by-N-by-P-by-... array. randn returns a scalar.  randn(SIZE(A)) returns
  962.     an array the same size as A.
  963.  
  964.     Note: The size inputs M, N, P, ... should be nonnegative integers.
  965.     Negative integers are treated as 0.
  966.  
  967.     R = randn(..., 'double') or R = randn(..., 'single') returns an array of
  968.     normal values of the specified class.
  969.  
  970.     The sequence of numbers produced by randn is determined by the settings of
  971.     the uniform random number generator that underlies RAND, randn, and RANDI.
  972.     randn uses one or more uniform random values to create each normal random
  973.     value.  Control that shared random number generator using RNG.
  974.  
  975.     Examples:
  976.  
  977.        Example 1: Generate values from a normal distribution with mean 1
  978.         and standard deviation 2.
  979.           r = 1 + 2.*randn(100,1);
  980.  
  981.        Example 2: Generate values from a bivariate normal distribution with
  982.        specified mean vector and covariance matrix.
  983.           mu = [1 2];
  984.           Sigma = [1 .5; .5 2]; R = chol(Sigma);
  985.           z = repmat(mu,100,1) + randn(100,2)*R;
  986.  
  987.        Example 3: Reset the random number generator used by RAND, RANDI, and
  988.        randn to its default startup settings, so that randn produces the same
  989.        random numbers as if you restarted MATLAB.
  990.           rng('default');
  991.           randn(1,5)
  992.  
  993.        Example 4: Save the settings for the random number generator used by
  994.        RAND, RANDI, and randn, generate 5 values from randn, restore the
  995.        settings, and repeat those values.
  996.           s = rng
  997.           z1 = randn(1,5)
  998.           rng(s);
  999.           z2 = randn(1,5) % z2 contains exactly the same values as z1
  1000.  
  1001.        Example 5: Reinitialize the random number generator used by RAND,
  1002.        RANDI, and randn with a seed based on the current time.  randn will
  1003.        return different values each time you do this.  NOTE: It is usually
  1004.        not necessary to do this more than once per MATLAB session.
  1005.           rng('shuffle');
  1006.           randn(1,5)
  1007.  
  1008.     See Updating Your Random Number Generator Syntax to use RNG to replace
  1009.     randn with the 'seed' or 'state' inputs.
  1010.  
  1011.     See also rand, randi, rng, RandStream, RandStream/randn
  1012.  
  1013.     Overloaded methods:
  1014.        RandStream/randn
  1015.        distributed/randn
  1016.        codistributor2dbc/randn
  1017.        codistributor1d/randn
  1018.        codistributed/randn
  1019.        gpuArray/randn
  1020.  
  1021.     Reference page in Help browser
  1022.        doc randn
  1023.  
  1024. >> %funkcja randn zwraca probki o rozkladzie noramlnym, czyli gaussowaskim
  1025. >> szum=randn(1,10)
  1026.  
  1027. szum =
  1028.  
  1029.     0.5377    1.8339   -2.2588    0.8622    0.3188   -1.3077   -0.4336    0.3426    3.5784    2.7694
  1030.  
  1031. >> %sygnal losowy o rozkladzie gaussowskim
  1032. >> szum_rown=rand(2,5)
  1033.  
  1034. szum_rown =
  1035.  
  1036.     0.1576    0.9572    0.8003    0.4218    0.7922
  1037.     0.9706    0.4854    0.1419    0.9157    0.9595
  1038.  
  1039. >> % wyzej - sygnal o rozkladzie rownomiernym
  1040. >> %na przedziale ten sygnal jest 0 , 1
  1041. >> srednia = mean(szum)
  1042.  
  1043. srednia =
  1044.  
  1045.     0.6243
  1046.  
  1047. >> %wartosc srednia
  1048. >> szum=randn(1,1000); srednia=mean(szum)
  1049.  
  1050. srednia =
  1051.  
  1052.    -0.0460
  1053.  
  1054. >> %cztery funkcje ktore dotycza zaokraglenie
  1055. >> ceil(5.3)
  1056.  
  1057. ans =
  1058.  
  1059.      6
  1060.  
  1061. >> %zawsdze w gore
  1062. >> floor(3.8)
  1063.  
  1064. ans =
  1065.  
  1066.      3
  1067.  
  1068. >> fix(6.7)
  1069.  
  1070. ans =
  1071.  
  1072.      6
  1073.  
  1074. >> fix(-4.8)
  1075.  
  1076. ans =
  1077.  
  1078.     -4
  1079.  
  1080. >> %zawsze w kierunku zera - fix
  1081. >> round(13.4)
  1082.  
  1083. ans =
  1084.  
  1085.     13
  1086.  
  1087. >> %round zaokraglenie
  1088. >> fix(2.7)
  1089.  
  1090. ans =
  1091.  
  1092.      2
  1093.  
  1094. >> round(2.7)
  1095.  
  1096. ans =
  1097.  
  1098.      3
  1099.  
  1100. >> %TABLICE ZNAKOWE
  1101. >> txt1='Ulubiona ksiazka'
  1102.  
  1103. txt1 =
  1104.  
  1105. Ulubiona ksiazka
  1106.  
  1107. >> txt2='Ala ma kota'
  1108.  
  1109. txt2 =
  1110.  
  1111. Ala ma kota
  1112.  
  1113. >> tekst = [txt1, ':', txt2]
  1114.  
  1115. tekst =
  1116.  
  1117. Ulubiona ksiazka:Ala ma kota
  1118.  
  1119. >> tekst = [txt1, ' : ', txt2]
  1120.  
  1121. tekst =
  1122.  
  1123. Ulubiona ksiazka : Ala ma kota
  1124.  
  1125. >> %symulacja rzutu kostka
  1126. >> rzut=rand(1,1)
  1127.  
  1128. rzut =
  1129.  
  1130.     0.5301
  1131.  
  1132. >> rzut=6*rand(1,1)
  1133.  
  1134. rzut =
  1135.  
  1136.     1.6504
  1137.  
  1138. >> rzut=floor(6*rand(1,1))
  1139.  
  1140. rzut =
  1141.  
  1142.      1
  1143.  
  1144. >> rzut=floor(rand(1,1)) +1
  1145.  
  1146. rzut =
  1147.  
  1148.      1
  1149.  
  1150. >> rzut = floor(6*rand(1,5)) +1
  1151.  
  1152. rzut =
  1153.  
  1154.      2     5     6     1     4
  1155.  
  1156. >> rzut = floor(6*rand(1,5)) +1
  1157.  
  1158. rzut =
  1159.  
  1160.      1     5     6     1     6
  1161.  
  1162. >> rzut = floor(6*rand(1,5)) +1
  1163.  
  1164. rzut =
  1165.  
  1166.      1     5     5     4     6
  1167.  
  1168. >> rzut = floor(6*rand(1,5)) +1
  1169.  
  1170. rzut =
  1171.  
  1172.      6     4     1     2     2
  1173.  
  1174. >> rzut = floor(6*rand(1,5)) +1
  1175.  
  1176. rzut =
  1177.  
  1178.      1     1     4     6     3
  1179.  
  1180. >> rzut = floor(6*rand(1,5)) +1
  1181.  
  1182. rzut =
  1183.  
  1184.      3     6     6     5     6
  1185.  
  1186. >> %za kazdym nastepnym razem wywolanai tej funkcja sa inne wartosci
  1187. >> %FUNKCJE TRYGONOMETRYCZNE
  1188. >> A=3 %amplituda
  1189.  
  1190. A =
  1191.  
  1192.      3
  1193.  
  1194. >> f=2 %czestotliwosc
  1195.  
  1196. f =
  1197.  
  1198.      2
  1199.  
  1200. >> t=0:0.01:1 %wektor czasu
  1201.  
  1202. t =
  1203.  
  1204.   Columns 1 through 12
  1205.  
  1206.          0    0.0100    0.0200    0.0300    0.0400    0.0500    0.0600    0.0700    0.0800    0.0900    0.1000    0.1100
  1207.  
  1208.   Columns 13 through 24
  1209.  
  1210.     0.1200    0.1300    0.1400    0.1500    0.1600    0.1700    0.1800    0.1900    0.2000    0.2100    0.2200    0.2300
  1211.  
  1212.   Columns 25 through 36
  1213.  
  1214.     0.2400    0.2500    0.2600    0.2700    0.2800    0.2900    0.3000    0.3100    0.3200    0.3300    0.3400    0.3500
  1215.  
  1216.   Columns 37 through 48
  1217.  
  1218.     0.3600    0.3700    0.3800    0.3900    0.4000    0.4100    0.4200    0.4300    0.4400    0.4500    0.4600    0.4700
  1219.  
  1220.   Columns 49 through 60
  1221.  
  1222.     0.4800    0.4900    0.5000    0.5100    0.5200    0.5300    0.5400    0.5500    0.5600    0.5700    0.5800    0.5900
  1223.  
  1224.   Columns 61 through 72
  1225.  
  1226.     0.6000    0.6100    0.6200    0.6300    0.6400    0.6500    0.6600    0.6700    0.6800    0.6900    0.7000    0.7100
  1227.  
  1228.   Columns 73 through 84
  1229.  
  1230.     0.7200    0.7300    0.7400    0.7500    0.7600    0.7700    0.7800    0.7900    0.8000    0.8100    0.8200    0.8300
  1231.  
  1232.   Columns 85 through 96
  1233.  
  1234.     0.8400    0.8500    0.8600    0.8700    0.8800    0.8900    0.9000    0.9100    0.9200    0.9300    0.9400    0.9500
  1235.  
  1236.   Columns 97 through 101
  1237.  
  1238.     0.9600    0.9700    0.9800    0.9900    1.0000
  1239.  
  1240. >> s=A*sin(2*pi*f*t) % sygnal
  1241.  
  1242. s =
  1243.  
  1244.   Columns 1 through 12
  1245.  
  1246.          0    2.7279   -2.2704   -0.8382    2.9681   -1.6321   -1.6097    2.9718   -0.8637   -2.2530    2.7388   -0.0266
  1247.  
  1248.   Columns 13 through 24
  1249.  
  1250.    -2.7167    2.2877    0.8127   -2.9641    1.6543    1.5872   -2.9753    0.8891    2.2353   -2.7496    0.0531    2.7054
  1251.  
  1252.   Columns 25 through 36
  1253.  
  1254.    -2.3048   -0.7871    2.9599   -1.6764   -1.5647    2.9786   -0.9144   -2.2175    2.7601   -0.0797   -2.6938    2.3217
  1255.  
  1256.   Columns 37 through 48
  1257.  
  1258.     0.7615   -2.9554    1.6983    1.5419   -2.9817    0.9397    2.1996   -2.7704    0.1062    2.6820   -2.3384   -0.7358
  1259.  
  1260.   Columns 49 through 60
  1261.  
  1262.     2.9508   -1.7201   -1.5191    2.9845   -0.9649   -2.1814    2.7805   -0.1327   -2.6700    2.3549    0.7100   -2.9459
  1263.  
  1264.   Columns 61 through 72
  1265.  
  1266.     1.7418    1.4961   -2.9871    0.9900    2.1631   -2.7903    0.1593    2.6578   -2.3713   -0.6842    2.9407   -1.7634
  1267.  
  1268.   Columns 73 through 84
  1269.  
  1270.    -1.4731    2.9894   -1.0150   -2.1446    2.8000   -0.1858   -2.6454    2.3875    0.6583   -2.9354    1.7848    1.4499
  1271.  
  1272.   Columns 85 through 96
  1273.  
  1274.    -2.9915    1.0399    2.1260   -2.8094    0.2123    2.6327   -2.4035   -0.6323    2.9298   -1.8061   -1.4266    2.9934
  1275.  
  1276.   Columns 97 through 101
  1277.  
  1278.    -1.0648   -2.1072    2.8186   -0.2387   -2.6199
  1279.  
  1280. >> plot(t,s)
  1281. >> grid on
  1282. >> %ZAPIS DO PLIKU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement