Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Чистим экран
- clc;
- clear variables;
- %% #2. Матрицы
- A = rand(6);
- B = rand(6);
- v = rand(6,1);
- w1 = rand(6,1);
- % Подсчет С
- C = (A*B-B/A)*v*w1';
- % Вывод
- fprintf('Максимальное значение матрицы А: %5.5f \n',max(max(A)));
- fprintf('Минимальное значение матрицы А: %5.5f \n',min(min(A)));
- fprintf('Среднее значение матрицы А: %5.5f \n',mean(mean(A)));
- fprintf('Максимальное значение матрицы В: %5.5f \n',max(max(B)));
- fprintf('Минимальное значение матрицы В: %5.5f \n',min(min(B)));
- fprintf('Среднее значение матрицы В: %5.5f \n',mean(mean(B)));
- fprintf('Размер матрицы С: %ux%u \n',size(C));
- disp(C);
- %Гистограммы
- D = [v, w1];
- fprintf('Размер матрицы D: %ux%u \n',size(D));
- disp(D);
- figure('Name','Bar','NumberTitle','off');
- bar(D);
- e = bar(D);
- e(1).FaceColor = 'red';
- e(2).FaceColor = 'green';
- title('Vectors \itv \rm\bfand \itw');
- legend('Vector \itv','Vector \itw','Location','bestoutside');
- %% #3.1
- t = (0 : 0.001 : 1)';
- f = 2;
- w = 2*pi*f;
- y = cos(w*t);
- z = randn(length(y),1);
- q = wgn(length(y),1,0);
- % #3.2
- y1 = y + z;
- y2 = y + q;
- y3 = awgn(y,10);
- Y = [t, y, y1, y2, y3];
- % Сохранение
- save('.mat', 'Y');
- dlmwrite('.csv', Y, 'delimiter', ';');
- fileID = fopen('.txt', 'w');
- for i = 1 : 1 : size(Y, 1)
- for j = 1 : 1 : size(Y, 2)
- fprintf(fileID, '%.4f; ', Y(i, j));
- end
- fprintf(fileID, '\n');
- end
- fclose(fileID);
- %% #3.3
- figure('Name','Plotting','NumberTitle','off');
- % plot
- subplot(3, 1, 1);
- plot(t, y, 'g', 'Marker', ' x ');
- title('By-points plotting');
- xlabel('time (sec.)');
- ylabel('cos(\omega*t)');
- grid on;
- % stair
- subplot(3, 1, 2);
- stairs(t, y, 'r');
- title('Stairs plotting');
- xlabel('time (sec.)');
- ylabel('cos(\omega*t)');
- grid on;
- % stem
- subplot(3, 1, 3);
- stem(t, y, 'b');
- title('Stem plotting');
- xlabel('time (sec.)');
- ylabel('cos(\omega*t)');
- grid on;
- %% #3.4
- figure('Name','Awgn','NumberTitle','off');
- % Signal #1
- subplot(3, 1, 1);
- plot(t, Y(:,3), 'Color', 'green');
- hold on;
- plot(t, Y(:,2), 'Color', 'black', 'LineWidth', 3);
- hold off;
- legend('Signal with AWGN','Original signal','Location','bestoutside');
- title('Signal #1');
- xlabel('time (sec.)');
- ylabel('y1(t)');
- grid on;
- % Signal #2
- subplot(3, 1, 2);
- plot(t, Y(:,4), 'Color', 'green');
- hold on;
- plot(t, Y(:,2), 'Color', 'black', 'LineWidth', 3);
- hold off;
- legend('Signal with AWGN','Original signal','Location','bestoutside');
- title('Signal #2');
- xlabel('time (sec.)');
- ylabel('y2(t)');
- grid on;
- % Signal #3
- subplot(3, 1, 3);
- plot(t, Y(:,5), 'Color', 'green');
- hold on;
- plot(t, Y(:,2), 'Color', 'black', 'LineWidth', 3);
- hold off;
- legend('Signal with AWGN','Original signal','Location','bestoutside');
- title('Signal #3');
- xlabel('time (sec.)');
- ylabel('y3(t)');
- grid on;
- %% #4.1
- [X, Y] = meshgrid(-4 : 0.1 : 4, -4 : 0.1 : 4);
- R = (X.^2 + Y.^2).^0.5 + X.^2 + Y.^2;
- Z = sin(R)./R;
- figure('Name','Surface','NumberTitle','off');
- % left up
- sp_lu = subplot(2, 3, 1);
- surf(Z);
- view(240, 25);
- title('surf(sin(R)/R))');
- xlabel('x');
- ylabel('y');
- zlabel('z');
- % left down
- sp_ld = subplot(2, 3, 4);
- mesh(Z);
- view(240, 25);
- title('mesh(sin(R)/R))');
- xlabel('x');
- ylabel('y');
- zlabel('z');
- % all right
- sp_alr = subplot(2, 3, [2 3 5 6]);
- s = surf(Z);
- view(240, 15);
- title('advanced surf(sin(R)/R))');
- xlabel('x');
- ylabel('y');
- zlabel('z');
- s.FaceColor = 'interp';
- s.EdgeColor = 'none';
- %% #4.2
- colormap(sp_lu, jet);
- colormap(sp_ld, spring);
- colormap(sp_alr, cool);
- colorbar(sp_alr, 'Location', 'southoutside');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement