-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab1.m
64 lines (51 loc) · 959 Bytes
/
lab1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
clc; clear all; close all;
a = 1;
b = 2;
sum = a + b
a^2;
s = sqrt(a)
%matrix
A = [1 2]
B = [3 4; 5 6]
C = [1 2 3; 4 5 6]
% linspace (equispaced)
aa = 0;
bb = 1;
num = 5;
grid1 = linspace(aa,bb,num)
% defined spacing
cc = 0;
dd = 1;
spacing = 0.2;
grid2 = cc:spacing:dd
% matrices
D = [1 2 3; 3 4 5];
E = [44 55 66; 11 22 33];
F = [1 2;3 4;5 6];
sum1 = D + E
product1 = D.*E % element wise multiplication
product2 = E*F % usual multiplication
division1 = D./E % element wise division
% matrices with all elements 1
I1 = ones(3)
I2 = ones(1,3)
I3 = ones(2,5)
% matrices with all elements 0
Z1 = zeros(3)
Z2 = zeros(2,3)
% identity matrix
E1 = eye(3)
disp(A)
% diagonal matrix
diag(A)
diag(A,1) % super diagonal
diag(A,-1) % sub diagonal
% vector % plot
x = linspace(0,10,50); % grid
y = sin(10*x); % function
plot(x,y,'linewidth',2); % plot
% determinant
S = [1 2 6; 3 4 5; 6 8 9];
det(S)
% accessing any element of a matrix
S(2,3)