Mudanças entre as edições de "FIC MATLAB 2018-1/Aula-3"
Ir para navegação
Ir para pesquisar
(Criou página com '<syntaxhighlight lang=matlab class="mw-collapsible"> </syntaxhighlight>') |
|||
Linha 1: | Linha 1: | ||
<syntaxhighlight lang=matlab class="mw-collapsible"> | <syntaxhighlight lang=matlab class="mw-collapsible"> | ||
− | + | %-- 20-03-2018 19:05:56 --% | |
+ | % Operações com matrizes e vetores | ||
+ | A = [10 20 30; 3 2 1] | ||
+ | B = [0 0 0; 5 5 5] | ||
+ | format compact | ||
+ | A + B | ||
+ | C = [1 2; 10 100] | ||
+ | A + C | ||
+ | A | ||
+ | B | ||
+ | A - B | ||
+ | A0 = [1 2; 3 4]; | ||
+ | B0 = [5 0; 10 20]; | ||
+ | A0 * B0 | ||
+ | A | ||
+ | B | ||
+ | A * B | ||
+ | A0 | ||
+ | A0 * A | ||
+ | A * A0 | ||
+ | A0 * B0 | ||
+ | B0 * A0 | ||
+ | A0 | ||
+ | B0 | ||
+ | A0 .* B0 | ||
+ | A0 ./ B0 | ||
+ | A0 .+ B0 | ||
+ | A0 + B0 | ||
+ | A | ||
+ | A0 | ||
+ | A0^2 | ||
+ | A*A | ||
+ | A0*A0 | ||
+ | A0 .^ 2 | ||
+ | v = linspace(1, 10, 10) | ||
+ | v = 1:10 | ||
+ | v .^ 2 | ||
+ | (1:10) .^ 2 | ||
+ | A0 | ||
+ | A0 .^ 4 | ||
+ | 2 .^ A | ||
+ | 2 .^ A0 | ||
+ | A0 | ||
+ | A0 .^ (1/3) | ||
+ | A0 .^ 0.2 | ||
+ | 1:10 | ||
+ | 2 .^ (1:10) | ||
+ | 2 .^ 1:10 | ||
+ | (2 .^ 1):10 | ||
+ | 2 .^ (1:10) | ||
+ | 2 .^ A0 | ||
+ | 2 ^ A0 | ||
+ | A0 | ||
+ | sin(A0) | ||
+ | sin(1) | ||
+ | sin(2) | ||
+ | exp(A0) | ||
+ | expm(A0) | ||
+ | 2^A0 | ||
+ | 2.^A0 | ||
+ | B0 | ||
+ | B | ||
+ | C | ||
+ | D = [1 2 3; -1 -2 -10] | ||
+ | abs(D) | ||
+ | help expm | ||
+ | doc expm | ||
+ | A | ||
+ | A * 5 | ||
+ | 5 * A | ||
+ | A | ||
+ | A / 2 | ||
+ | 2 / A | ||
+ | 2 ./ A | ||
+ | A | ||
+ | A + 3 | ||
+ | A - 3 | ||
+ | 3 - A | ||
+ | A | ||
+ | A/2 | ||
+ | A / 2 | ||
+ | A /2 | ||
+ | A/ 2 | ||
+ | v = [1 2 3 4] | ||
+ | sum(v) | ||
+ | prod(v) | ||
+ | 1:10 | ||
+ | prod(1:10) | ||
+ | factorial(10) | ||
+ | A | ||
+ | sum(A) | ||
+ | v | ||
+ | [v;v;v] | ||
+ | sum(ans) | ||
+ | A | ||
+ | sum(A) | ||
+ | doc sum | ||
+ | sum(A, 1) | ||
+ | sum(A, 2) | ||
+ | sum(A') | ||
+ | sum(A')' | ||
+ | A | ||
+ | sum(sum(A)) | ||
+ | sum(A) | ||
+ | sum(sum(A)) | ||
+ | v | ||
+ | min(v) | ||
+ | max(v) | ||
+ | A | ||
+ | min(A) | ||
+ | max(A) | ||
+ | max(A, 2) | ||
+ | doc max | ||
+ | max(A, [], 2) | ||
+ | A | ||
+ | max(A, [], 2) | ||
+ | max(1, 3, 2, 4, 1, 6) | ||
+ | v = [1 2 1 3 5 2 0 | ||
+ | ] | ||
+ | sum(v) / length(v) | ||
+ | mean(v) | ||
+ | norm(v) | ||
+ | norm([3 4]) | ||
+ | norm(v) | ||
+ | sqrt(sum(v. ^ 2)) | ||
+ | sqrt(sum(v .^ 2)) | ||
+ | A | ||
+ | A0 | ||
+ | det(A0) | ||
+ | inv(A) | ||
+ | inv(A0) | ||
+ | A0 * inv(A0) | ||
+ | 1:20 | ||
+ | reshape(1:20, 4, 5) | ||
+ | reshape(1:20, 5, 4)' | ||
+ | exp(1) | ||
+ | a = [3 4] | ||
+ | norm(a) | ||
+ | abs(a) | ||
+ | 1 / (1:10000).^2 | ||
+ | 1 ./ ((1:10000).^2) | ||
+ | sum(1 ./ ((1:10000).^2)) | ||
+ | 6 * sum(1 ./ ((1:10000).^2)) | ||
+ | sqrt(6 * sum(1 ./ ((1:10000).^2))) | ||
+ | format long | ||
+ | sqrt(6 * sum(1 ./ ((1:10000).^2))) | ||
+ | sqrt(6 * sum(1 ./ ((1:100000).^2))) | ||
+ | x = sum(1 ./ ((1:100000).^2)) | ||
+ | x = sum(1 ./ ((1:10000).^2)) | ||
+ | sqrt(6 * x) | ||
+ | x = sum(1 ./ ((1:1000000).^2)); sqrt(6*x) | ||
+ | pi | ||
+ | x = sum(1 ./ ((1:1000).^2)); sqrt(6*x) | ||
+ | x = sum(1 ./ (1:100)) | ||
+ | x = sum(1 ./ (1:1000)) | ||
+ | x = sum(1 ./ (1:10000)) | ||
+ | x = sum(1 ./ (1:100000)) | ||
+ | % Plots | ||
+ | clc | ||
+ | x = [1 2 5] | ||
+ | y = [-10 0 2] | ||
+ | plot(x, y) | ||
+ | plot(x,y) | ||
+ | stem(x, y) | ||
+ | x = [1 2 5 7] | ||
+ | y = [-10 0 2 2] | ||
+ | stem(x, y) | ||
+ | bar(x, y) | ||
+ | plot(x, y) | ||
+ | stairs(x, y) | ||
+ | plot(x, y) | ||
+ | y | ||
+ | plot(y) | ||
+ | x0 = [1 20 25] | ||
+ | plot(x0, y) | ||
+ | x = linspace(0, 2*pi, 10) | ||
+ | format short | ||
+ | x = linspace(0, 2*pi, 10) | ||
+ | y = sin(x) | ||
+ | plot(x, y) | ||
+ | x = linspace(0, 2*pi, 100) | ||
+ | y = sin(x) | ||
+ | x = linspace(0, 2*pi, 100); | ||
+ | y = sin(x); | ||
+ | plot(x, y) | ||
+ | stem(x, y) | ||
+ | bar(x, y) | ||
+ | stairs(x, y) | ||
+ | plot(x, y) | ||
+ | plot(x, y.^2) | ||
+ | plot(x, sin(x)) | ||
+ | hold on | ||
+ | plot(x, cos(x)) | ||
+ | stem(x, -cos(x)) | ||
+ | hold off | ||
+ | x | ||
+ | plot(x, x.^2) | ||
+ | grid on | ||
+ | plot(x, x.^2) | ||
+ | grid on | ||
+ | grid off | ||
+ | grid on | ||
+ | xlabel('posicao') | ||
+ | ylabel('temperatura') | ||
+ | title('Temperatura de uma barra em funcao da posicao') | ||
+ | x0 = [1 20 25 27] | ||
+ | x = [1 2 5 7] | ||
+ | y = [-10 0 2 2] | ||
+ | stem(x, y) | ||
+ | doc xlim | ||
+ | xlim([0 8]) | ||
+ | ylim([-11 3]) | ||
+ | axis([0 8 -11 3]) | ||
+ | x = linspace(0, 2*pi, 100); | ||
+ | plot(x, sin(x)) | ||
+ | hold on | ||
+ | plot(x, cos(x)) | ||
+ | doc legend | ||
+ | legend('seno', 'cosseno') | ||
+ | plot(x, sin(x), 'g--') | ||
+ | plot(x, sin(x), 'm-.') | ||
+ | plot(x, sin(x), 'm-.x') | ||
+ | plot(x, sin(x), 'y--o') | ||
+ | plot(x, sin(x), '--oy') | ||
+ | plot(x, sin(x), 'o--y') | ||
+ | plot(x, sin(x), 'y--o') | ||
+ | plot(x, sin(x), "y--o") | ||
+ | plot(x, sin(x), 'y--o') | ||
+ | doc plot | ||
+ | plot(x, sin(x), '--o', 'Color', [255 128 0]) | ||
+ | plot(x, sin(x), '--o', 'Color', [1 0.5 0]) | ||
+ | plot(x, sin(x), '--o', 'Color', [1 0.5 0], 'LineWidth', 4) | ||
+ | plot(x, sin(x), 'm--o') | ||
+ | plot(x, sin(x), 'k-p') | ||
+ | plot(x, sin(x), 'k-p', 'MarkerSize', 15) | ||
+ | hold on | ||
+ | plot(x, cos(x), 'm-.v', 'MarkerSize', 15) | ||
+ | legend('seno', 'cosseno') | ||
+ | plot(2, -0.4, 'm-.v', 'MarkerSize', 15) | ||
+ | plot(x, sin(x), 'k-p', 'MarkerSize', 15) | ||
+ | hold on | ||
+ | plot(x, cos(x), 'm-.') | ||
+ | plot(2, cos(2), 'm-.v', 'MarkerSize', 15) | ||
</syntaxhighlight> | </syntaxhighlight> |
Edição atual tal como às 21h51min de 20 de março de 2018
%-- 20-03-2018 19:05:56 --%
% Operações com matrizes e vetores
A = [10 20 30; 3 2 1]
B = [0 0 0; 5 5 5]
format compact
A + B
C = [1 2; 10 100]
A + C
A
B
A - B
A0 = [1 2; 3 4];
B0 = [5 0; 10 20];
A0 * B0
A
B
A * B
A0
A0 * A
A * A0
A0 * B0
B0 * A0
A0
B0
A0 .* B0
A0 ./ B0
A0 .+ B0
A0 + B0
A
A0
A0^2
A*A
A0*A0
A0 .^ 2
v = linspace(1, 10, 10)
v = 1:10
v .^ 2
(1:10) .^ 2
A0
A0 .^ 4
2 .^ A
2 .^ A0
A0
A0 .^ (1/3)
A0 .^ 0.2
1:10
2 .^ (1:10)
2 .^ 1:10
(2 .^ 1):10
2 .^ (1:10)
2 .^ A0
2 ^ A0
A0
sin(A0)
sin(1)
sin(2)
exp(A0)
expm(A0)
2^A0
2.^A0
B0
B
C
D = [1 2 3; -1 -2 -10]
abs(D)
help expm
doc expm
A
A * 5
5 * A
A
A / 2
2 / A
2 ./ A
A
A + 3
A - 3
3 - A
A
A/2
A / 2
A /2
A/ 2
v = [1 2 3 4]
sum(v)
prod(v)
1:10
prod(1:10)
factorial(10)
A
sum(A)
v
[v;v;v]
sum(ans)
A
sum(A)
doc sum
sum(A, 1)
sum(A, 2)
sum(A')
sum(A')'
A
sum(sum(A))
sum(A)
sum(sum(A))
v
min(v)
max(v)
A
min(A)
max(A)
max(A, 2)
doc max
max(A, [], 2)
A
max(A, [], 2)
max(1, 3, 2, 4, 1, 6)
v = [1 2 1 3 5 2 0
]
sum(v) / length(v)
mean(v)
norm(v)
norm([3 4])
norm(v)
sqrt(sum(v. ^ 2))
sqrt(sum(v .^ 2))
A
A0
det(A0)
inv(A)
inv(A0)
A0 * inv(A0)
1:20
reshape(1:20, 4, 5)
reshape(1:20, 5, 4)'
exp(1)
a = [3 4]
norm(a)
abs(a)
1 / (1:10000).^2
1 ./ ((1:10000).^2)
sum(1 ./ ((1:10000).^2))
6 * sum(1 ./ ((1:10000).^2))
sqrt(6 * sum(1 ./ ((1:10000).^2)))
format long
sqrt(6 * sum(1 ./ ((1:10000).^2)))
sqrt(6 * sum(1 ./ ((1:100000).^2)))
x = sum(1 ./ ((1:100000).^2))
x = sum(1 ./ ((1:10000).^2))
sqrt(6 * x)
x = sum(1 ./ ((1:1000000).^2)); sqrt(6*x)
pi
x = sum(1 ./ ((1:1000).^2)); sqrt(6*x)
x = sum(1 ./ (1:100))
x = sum(1 ./ (1:1000))
x = sum(1 ./ (1:10000))
x = sum(1 ./ (1:100000))
% Plots
clc
x = [1 2 5]
y = [-10 0 2]
plot(x, y)
plot(x,y)
stem(x, y)
x = [1 2 5 7]
y = [-10 0 2 2]
stem(x, y)
bar(x, y)
plot(x, y)
stairs(x, y)
plot(x, y)
y
plot(y)
x0 = [1 20 25]
plot(x0, y)
x = linspace(0, 2*pi, 10)
format short
x = linspace(0, 2*pi, 10)
y = sin(x)
plot(x, y)
x = linspace(0, 2*pi, 100)
y = sin(x)
x = linspace(0, 2*pi, 100);
y = sin(x);
plot(x, y)
stem(x, y)
bar(x, y)
stairs(x, y)
plot(x, y)
plot(x, y.^2)
plot(x, sin(x))
hold on
plot(x, cos(x))
stem(x, -cos(x))
hold off
x
plot(x, x.^2)
grid on
plot(x, x.^2)
grid on
grid off
grid on
xlabel('posicao')
ylabel('temperatura')
title('Temperatura de uma barra em funcao da posicao')
x0 = [1 20 25 27]
x = [1 2 5 7]
y = [-10 0 2 2]
stem(x, y)
doc xlim
xlim([0 8])
ylim([-11 3])
axis([0 8 -11 3])
x = linspace(0, 2*pi, 100);
plot(x, sin(x))
hold on
plot(x, cos(x))
doc legend
legend('seno', 'cosseno')
plot(x, sin(x), 'g--')
plot(x, sin(x), 'm-.')
plot(x, sin(x), 'm-.x')
plot(x, sin(x), 'y--o')
plot(x, sin(x), '--oy')
plot(x, sin(x), 'o--y')
plot(x, sin(x), 'y--o')
plot(x, sin(x), "y--o")
plot(x, sin(x), 'y--o')
doc plot
plot(x, sin(x), '--o', 'Color', [255 128 0])
plot(x, sin(x), '--o', 'Color', [1 0.5 0])
plot(x, sin(x), '--o', 'Color', [1 0.5 0], 'LineWidth', 4)
plot(x, sin(x), 'm--o')
plot(x, sin(x), 'k-p')
plot(x, sin(x), 'k-p', 'MarkerSize', 15)
hold on
plot(x, cos(x), 'm-.v', 'MarkerSize', 15)
legend('seno', 'cosseno')
plot(2, -0.4, 'm-.v', 'MarkerSize', 15)
plot(x, sin(x), 'k-p', 'MarkerSize', 15)
hold on
plot(x, cos(x), 'm-.')
plot(2, cos(2), 'm-.v', 'MarkerSize', 15)