[go: up one dir, main page]

0% found this document useful (0 votes)
5 views31 pages

Computer Programing #2

Uploaded by

leeseoeum1219
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views31 pages

Computer Programing #2

Uploaded by

leeseoeum1219
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Computer Programing

Gangmin Kim
School of Energy System Engineering
Cinema Laboratory
kkm371837@cau.ac.kr
Today’s Topic
• Command and Input for MATLAB • Basic Array by Matrix and Vector
• (Prompt) (Script) • (Arrays)
• • (Vector)
• • (Matrix)
• Operator and Calculation • How to Plot


• Commander and Variables
• (Work Session)
• MATLAB .
, !

2 2025-1 Computer Programming


Command and
Input for MATLAB
(Prompt)
• (>>) / Example


.( /
)
• ,
(Variable) .
• C
, MATLAB
.

4 2025-1 Computer Programming


(Script)
• ( ) / Example

( )
• ,
.

.
• (%)
• ,
(*.m)

5 2025-1 Computer Programming


(Prompt) (Script)
Prompt Script
• , • MATLAB .
. •
• .

MATLAB , .
.

6 2025-1 Computer Programming


+ /

+ .\

- \

- .^

.* ^

* .’

./ ‘

7 2025-1 Computer Programming


(Error Estimation)
• (Error)
• , MATLAB
.

.
• (Syntax error) ,
(runtime error,
round-off error ) .

8 2025-1 Computer Programming


Example
• 1) .

9 2025-1 Computer Programming


Operator and
Calculator
‘=‘
• , ‘=‘ Example

• .
• .

.

“ ” “ ” .
!

11 2025-1 Computer Programming


&
== Example
• •

== & AND

~= | OR
AND(
> &&
)
OR(
>= ||
)

< ~ NOT

<=

12 2025-1 Computer Programming


명령 Description 예시 Example

Format short 소수점 아래 4자리 13.6745

Format long 소수점 아래 16자리 17.2748402946355

Format short e 소수아래 4자리와 지수 6.3792E+03

Format long e 소수아래 16자리와 지수 6.37924378478129E-04

13 2025-1 Computer Programming


Commander and
Variables
(Work Session)

clc

clear

clear v1 v2 v1 v2

Exist('name') ‘name’

quit MATLAB

who

whos

15 2025-1 Computer Programming


ans 가장 최근의 답

i,j 허수 ( )
!

inf 무한대

NaN Not a Number

pi 숫자

16 2025-1 Computer Programming


Example
• 2) .

>> pi

>> 1 + 3j

>> Complex(1, 3)

>> 1/0

>> 0/0

>> 7/2*i

>> 7/2i

17 2025-1 Computer Programming


Basic Array by
Matrix and Vector
(Array)
• ([ ]) .( ) Example
• MATLAB .

• ,
.
• , MATLAB

• Ex) [1, 2, 3 ; 4, 5, 6]

19 2025-1 Computer Programming


(Vector)

• (Scalar)
• ‘ ’ .( )
• 5, 10, 3.14

• (Vector)
• ‘ ’ ,
• )

20 2025-1 Computer Programming


(Vector)

! = $!! % !" % !# &% " = $"! % "" % "# &
• ,

• (Dot Product) —

• (Cross Product) —

21 2025-1 Computer Programming


(Matrix)
• (Matrix)
• (Row) (Column) 2
• .

• (Transpose)

• A AT .
• m×n (Transpose Matrix) n×m .
• EX)

22 2025-1 Computer Programming


(Matrix)

• / ! #!! """ #!! " ! $!! """ $!! " ! #!! + $!! """ #!! + $!! "
# $ # $ # $
• / # """ """ """ +
$ # """ """ """ =
$ # """ """ """ $
## $ # $ # $
• . % "! """ #"! & % $"! """ $"! & % #"! + $"! """ #"! + $"! &

• ! #!! """ #!! " ! $#!! """ $#!! "


# $ # $
• . $ # """ """ """ $ = # """ """ """ $
## $ # $
% "! """ #"! & % $#"! """ $#"! &

• (Row) (Column) .
• ,A ,B .

! #!! ### #!! "! $!! ### $!! " ! #!!$!! + #!"$"! + ### + #!!$"! ### #!!$!! + #!"$" ! + ### + #!!$"! "
# $# $ # $
# ### ### ### $# ### ### ### $ = # ### ### ### $
## $# $
% "! ### #"! &% $"! ### $"! & #% #"!$!! + #" "$"! + ### + # "!$"! ### #"!$!! + #" "$" ! + ### + # "!$"! $&

23 2025-1 Computer Programming


(Matrix)
• Determinant ( )
• (m × m ; Square Matrix) . ! !!! !!" "
"=% & # #$% " = !!!!"" $ !!" !"!
• detA |A| ' !"! !"" (
• ‘ ’ ( )

• 2×2

• 3×3

24 2025-1 Computer Programming


(Matrix)
• (Identity Matrix) !! " ""
• 1 , 0 . !! ""##" ! "$
# $ # $
• I . % " ! & # $
% " " ! &
• A , AI =A .

• (Inverse Matrix)
• A ,A I .
• A −1 .
" !!! !!" # !! ! " !"" !!!" #
"=% &$" = % &
' !"! !"" ( !!!!"" ! !!" !"! ' !!"! !!! (

25 2025-1 Computer Programming


(Matrix) MATLAB ,
, !
!


• n m

• .
• , AX =B . (A m × n, X, B n )
• !" = #
!!! !" = !!! #
A" = !!! #
" = !!! #

26 2025-1 Computer Programming


How to plot
Plot Commander

28 2025-1 Computer Programming


Plot
• Plot . Example

• 2

명령 Description

grid 그래프에 격자선을 그림

직교 좌표계 (Cartesian Coordinate)에 (x, y) 데이터를


plot(x,y) Plot Data
이용하여 그래프 생성

title(‘text1’) text1을 제목으로 사용

xlabel(‘text2’) text2를 x축 이름으로 사용

ylabel(‘text3’) text3를 y축 이름으로 사용

29 2025-1 Computer Programming


Example
• 3) .

30 2025-1 Computer Programming


THANK YOU FOR YOUR ATTENTION!!

You might also like