Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. %% Чистим экран
  2. clc;
  3. clear variables;
  4.  
  5. %% #2. Задаем матрицы
  6. A = randn(6);
  7. B = randn(6);
  8. v = randn(6,1);
  9. w1 = randn(6,1);
  10.  
  11. % Подсчеты
  12. C = (A*B-B/A)*v*w1';
  13.  
  14. % Вывод
  15. fprintf('Максимальное значение А: %5.5f \n',max(max(A)));
  16. fprintf('Минимальное значение А: %5.5f \n',min(min(A)));
  17. fprintf('Среднее значение А: %5.5f \n',mean(mean(A)));
  18. fprintf('Максимальное значение В: %5.5f \n',max(max(B)));
  19. fprintf('Минимальное значение В: %5.5f \n',min(min(B)));
  20. fprintf('Среднее значение В: %5.5f \n',mean(mean(B)));
  21. fprintf('Размер матрицы С: %ux%u \n',size(C));
  22. disp(C);
  23.  
  24. %Гистограммы
  25. D = [v, w1];
  26. fprintf('Размер матрицы D: %ux%u \n',size(D));
  27. disp(D);
  28.  
  29. figure('Name','Bar','NumberTitle','off');
  30. bar(D);
  31.  
  32. e = bar(D);
  33. e(1).FaceColor = 'red';
  34. e(2).FaceColor = 'green';
  35. title('Vectors \itv \rm\bfand \itw');
  36. legend('Vector \itv','Vector \itw','Location','bestoutside');
  37.  
  38. %% #3.1
  39. t = (0 : 0.001 : 1)';
  40. f = 2;
  41. w = 2*pi*f;
  42. y = cos(w * t);
  43. z = randn(length(y),1);
  44. q = wgn(length(y),1,0);
  45.  
  46. % #3.2
  47. y1 = y + z;
  48. y2 = y + q;
  49. y3 = awgn(y,10);
  50. Y = [t, y, y1, y2, y3];
  51.  
  52. % Сохранение
  53. save('.mat', 'Y');
  54. dlmwrite('.csv', Y, 'delimiter', ';');
  55. fileID = fopen('.txt', 'w');
  56. for i = 1 : 1 : size(Y, 1)
  57. for j = 1 : 1 : size(Y, 2)
  58. fprintf(fileID, '%.4f; ', Y(i, j));
  59. end
  60. fprintf(fileID, '\n');
  61. end
  62. fclose(fileID);
  63.  
  64. %% #3.3
  65. figure('Name','Plotting','NumberTitle','off');
  66.  
  67. % plot
  68. subplot(3, 1, 1);
  69. plot(t, y, 'g', 'Marker', ' x ');
  70. title('By-points plotting');
  71. xlabel('time (sec.)');
  72. ylabel('cos(\omega*t)');
  73. grid on;
  74.  
  75. % stair
  76. subplot(3, 1, 2);
  77. stairs(t, y, 'r');
  78. title('Stairs plotting');
  79. xlabel('time (sec.)');
  80. ylabel('cos(\omega*t)');
  81. grid on;
  82.  
  83. % stem
  84. subplot(3, 1, 3);
  85. stem(t, y, 'b');
  86. title('Stem plotting');
  87. xlabel('time (sec.)');
  88. ylabel('cos(\omega*t)');
  89. grid on;
  90.  
  91. %% #3.4
  92. figure('Name','Awgn','NumberTitle','off');
  93.  
  94. % Signal #1
  95. subplot(3, 1, 1);
  96. plot(t, Y(:,3), 'Color', 'green');
  97. hold on;
  98. plot(t, Y(:,2), 'Color', 'black', 'LineWidth', 3);
  99. hold off;
  100. legend('Signal with AWGN','Original signal','Location','bestoutside');
  101. title('Signal #1');
  102. xlabel('time (sec.)');
  103. ylabel('y1(t)');
  104. grid on;
  105.  
  106. % Signal #2
  107. subplot(3, 1, 2);
  108. plot(t, Y(:,4), 'Color', 'green');
  109. hold on;
  110. plot(t, Y(:,2), 'Color', 'black', 'LineWidth', 3);
  111. hold off;
  112. legend('Signal with AWGN','Original signal','Location','bestoutside');
  113. title('Signal #2');
  114. xlabel('time (sec.)');
  115. ylabel('y2(t)');
  116. grid on;
  117.  
  118. % Signal #3
  119. subplot(3, 1, 3);
  120. plot(t, Y(:,5), 'Color', 'green');
  121. hold on;
  122. plot(t, Y(:,2), 'Color', 'black', 'LineWidth', 3);
  123. hold off;
  124. legend('Signal with AWGN','Original signal','Location','bestoutside');
  125. title('Signal #3');
  126. xlabel('time (sec.)');
  127. ylabel('y3(t)');
  128. grid on;
  129.  
  130. %% #4.1
  131. [X, Y] = meshgrid(-4 : 0.1 : 4, -4 : 0.1 : 4);
  132. R = (X.^2 + Y.^2).^0.5 + X.^2 + Y.^2;
  133. Z = sin(R)./R;
  134.  
  135. figure('Name','Surface','NumberTitle','off');
  136.  
  137. % left up
  138. sp_lu = subplot(2, 3, 1);
  139. surf(Z);
  140. view(240, 25);
  141. title('surf(sin(R)/R))');
  142. xlabel('x');
  143. ylabel('y');
  144. zlabel('z');
  145.  
  146. % left down
  147. sp_ld = subplot(2, 3, 4);
  148. mesh(Z);
  149. view(240, 25);
  150. title('mesh(sin(R)/R))');
  151. xlabel('x');
  152. ylabel('y');
  153. zlabel('z');
  154.  
  155. % all right
  156. sp_alr = subplot(2, 3, [2 3 5 6]);
  157. s = surf(Z);
  158. view(240, 15);
  159. title('advanced surf(sin(R)/R))');
  160. xlabel('x');
  161. ylabel('y');
  162. zlabel('z');
  163. s.FaceColor = 'interp';
  164. s.EdgeColor = 'none';
  165.  
  166. %% #4.2
  167. colormap(sp_lu, jet);
  168. colormap(sp_ld, spring);
  169. colormap(sp_alr, cool);
  170.  
  171. colorbar(sp_alr, 'Location', 'southoutside');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement