[Matlab] practice_1

dewdew·2023년 6월 28일
0

Matlab & Simulink

목록 보기
1/6
post-thumbnail

[Matlab] 1일차 학습

학습 소스 링크 첨부 (01-05)

v = 1
v = [3,5]

i
j
i = 4
j = 6
i + j

% 변수 이름
namelengthmax

% cmd clear
clc

% 변수 할당
k = 4
k = k+1

% workspace(memory)
who
whos

% imaginary number
 % 다른 변수로 쓰고 있어도 의도적으로 * 를 빼서 표현하면 허수로 사용 가능
1i
2j
0.73j

% double point, no space anywhere!
a = 2.4e3
b = 0.037e+02
c = 31e-04

% format
format long e
pi
format long g
1e-08
1e-2
format compact
k = k + 1

% relative precision 두 숫자의 상태적인 유효숫자
format long e
1 + 1e-16 % 유효숫자 16개이기 때문에 결과는 1과 동일
1e100 + 1e84

% absolute precision
realmax
realmin

% inf / NaN(not a number)
1/0
0/0
a = nan
b = inf

% clearing variables
clear pi
pi
whos
clear sin i j
whos
sin(pi)
clear
whos

% help ** 
 % help who
 % doc who
help cosine
lookfor cosine % keyword
lookfor 'matrix inverse'

% arithmetic operator
format compact
1 / 3
3 / 1
(1 + 2) * (3 + 4)
1 + 2 * 3 + 4

a = magic([3]);
a
a = 1; b = 2; c = 3;
a, b, c

a = 3 + 3 + 3 ...
   + 5 * 3 + ...
    2

% array(matrix)
format long g
format compact
a = [1, 2 3];
b = [1 2 3;  4 5 6];
x = 1:6
x = 1: pi/50:pi % first : step : last
x = 0:-2:-5
x = linspace(0,10,10) % first, last, data number
b'
b1 = 1:0.2:2
b2 = rand(5,4) % gaussian, normally distributed form ...
% help rand 0-1 사이에서 난수 생성
b3 = ones(3,4)
b4 = zeros(8,3)
b5 = eye(3) % identity matrix(I)
rand(1,4)
rand(5,1)
rand(5,3)
1:4
isrow(rand(5,1))
iscolumn(rand(5,1))
[1:4]'
A = rand(4,3)
B = rand(4,3)
C = rand(3,3)
% A + B
% A * B'
% A' * B
% C^3 square matrix 이기 때문에 가능
% vectorization 통째로 계산해주는 기능(스칼라처럼), 루프를 안돌린다
A .* B
A ./ B
A .^ B

D = [ A', C ; rand(3,3) B'] % 3x4 + 3x3 ; 3x3 + 3x4 = 6x7 matrix combined

x = [] % empty array 2. array element 를 지울 때 사용
whos x
% 1. array 초기화 할 때
x = [x, 3]
x = [x, 3]
x = [x, 3]

% indexing "1-based!!!"
A = rand(6,4)
A(2,3)
r = rand(10,1)
r(3)
r(3:5)
r([3 4 5]) % index 에 대한 array
r([1 5 2 2 1])
r(4) = []
r(1)
size(r)
[m,n] = size(A)
size(A, 1)
size(A, 2)
% help size

A = rand(4,5)
A(2,3)
A(11) % column major mapping memory
A
%A(2:3, 1:2)
%A(3, 2:end)
A(2:3, :)
A(1:end, 2)



profile
연습장

0개의 댓글