# MATLAB 04-3

신예진·2022년 1월 27일
0

목록 보기
8/17

save

save aaa.mat % or save aaa

save aaa.mat a b % or save aaa a b

a = rand(3,2), b = rand(3,3)
save test.txt a b -ascii -double
type test.txt
load test.txt % all rows must have the same number of elements

2) directory commands

dir % list files in current directory
pwd % path of current directory
which (function) % (ex, which who), path of (function)
path % HOME > Set Path, path에 없는 폴더는 matlab이 거들떠도 안본다. 맨 위가 최우선 순위.

3) Linear system

solution of linear system (Ax = b)
3x1 + x2 + 2x3 = 1
2x1 + 2x2 + x3 = -3
x1 - 3x2 + 2x3 = 0

A = [3,1,2; 2,2,1; 1,-3,2]
b = [1;-3;0]
x = inv(A)*b % 주의 : transpose ' 와 inversion inv()은 다르다!

행렬의 역 변환은 가급적 피해야 한다. 대신 LU decomposition(소위 인수분해) 을 이용하는 것을 추천.
x = A\b % numerically stabe (by using LU decomposition)

4) Solution of Ax = b

① unique solution
# of variables = # of equations
x = inv(A)*b or x = A\b

② infinitely many solution
# of variables > # of equations
underdetermined system
minimum norm problem (x = A\b)
** Find x that satisfies Ax = b with minimum ∥x∥2

③ no solution
# of variables < # of equations
overdetermined system
least square problem (x = A\b)
** minimize ∥Ax-b∥2