MATLAB 02-1

신예진·2022년 1월 25일
0

Matlab Simulink

목록 보기
2/17

1) format for displaying numbers

format long e % displays in floating point with 16 significant digits
pi % 3.141592653589793e+00
format long g % displays in fixed point with 16 significant digits
pi % 3.141592653589793

format % displays in either fixed point or floating point (둘 중 알아서 보여준다)
    - 1e-8
    - 1e-2
    

2) suppressing blank lines

format compact

3) relative precision

format long e
1 + 1e-15 % 1.000000000000001e+00
1 + 1e-16 % 1 과 같은 수. 이유 : 매트랩의 유효숫자는 16개까지인데, 두 수가 있을때 16 이상 차이나면 없는 것으로 치부.
1e100 + 1e84 % 1.000000000000000e+100

4) absolute precision

realmax % 1.797693134862316e+308
realmin % 2.225073858507201e-308

5) Inf,NaN

1/0 % Inf
0/0 % NaN means Not a Number (=can be any number)
can type in small letters (ex. a = nan)

% inf, nan 둘 다 소문자로 입력해도 알아서 변환해서 저장해준다

6) clearing variables from memory

clear a b
clear % clears all variables from memory

7) help

help who
doc who
help cosine % there is no command called cosine
lookfor cosine % find command containing keywords
lookfor 'matrix inverse' % put more-than-two keywords in ''
    * most Matlab commands are in small letters

8) stop execution

ctrl-c

9) arithmetic operator

+ % addition
- % subtraction
* % multiplication
/ % division
\ % left division (a/b = b\a)
^ % power

    * above operator work for matrices (we will see later)
  

10) precedence

operation inside ()
^
*,/
+,-
left to right

11) semi colon at the end : no display

a = magic(3)
a = magic(3);

12) multiple expression in one line : comma or semicolon

a = 1, b = 2; c = 3

13) ...at the end : continuation (might need a blank in front)

a = 3 + 3 * 3 ... % 숫자 뒤에는 띄어서 '...' 붙여줘야 함
+ 5 * 3 +... % 연산자 뒤에는 공백 필요 없음
2

0개의 댓글