Matlab Basic1 - 2024
Matlab Basic1 - 2024
1
Outline
Time
• Mon. 10:30 – 12:00
Classroom
• 원흥관 318 ( 공용컴퓨터실 )
Course Assistant
• Min yeong Choi (010.4066.2453, [email protected], Room No. 8134 )
2
Outline
References:
• “ 제대로 배우는 MATLAB,” ( 방성완 , 한빛아카데미 , 2014)
• “The MathWorks, Inc - MATLAB Control System Toolbox Reference
(2018, The MathWorks, Inc)”
3
How to use MATLAB
http://kr.mathworks.com
4
How to use MATLAB
5
How to use MATLAB
6
How to use MATLAB
7
How to use MATLAB
Type pass-
word
8
How to use MATLAB
Click
9
How to use MATLAB
10
How to use MATLAB
11
How to use MATLAB
12
How to use MATLAB
13
How to use MATLAB
Simulink
Scroll down
Simscape
and check
Simulink Electrical
14
How to use MATLAB
MATLAB:
• This is a semi-word of the MATrix LABoratory, a computing tool that receives the matrix as ba-
sic input data and performs the process.
• Recently, Various tool-boxes (SIMULINK, Control SystemToolbox, Optimization Toolbox, ETC.) have been widely used
to solve various engineering problems.
15
How to use MATLAB
Window role
Current Folder Matlab displays the folder on which m-files are refer-
enced.
Command Window A window that receives user input.
Workspace To display information about variables.
16
How to use MATLAB
How to set up a path
• [ Home - Set Path(Environment) ]
17
How to use MATLAB
Editor(filename.m
)
18
How to use MATLAB
Editor(filename.m
)• Making a editior
19
How to use MATLAB
Command Window(CW) vs Editor(M-file)
• CW • Editor
20
How to use MATLAB
Command Window(CW) vs Editor(M-file)
• Caution
Suppose that you are using the editor.
Then, if your m-file is in the directory but it is not running,
Please check that you have properly defined your Set Path.
21
How to use MATLAB
who, whos
• It is difficult to remember all the variables and their values currently
in use.
• One of the best features of MATLAB is that all defined variables are
always stored in a workspace.
22
How to use MATLAB
who, whos
• Size=length(row)length(column)
• Class: Type of variables (Float,
Double, integer, etc.)
Whos Who
23
How to use MATLAB
Clear, Save, Load
• Clear: It can remove variables that you do not need to have mem-
ory capacity (clear variablename)
24
How to use MATLAB
Clear, Save, Load
25
How to use MATLAB
Format short, Format long, Format short e
Type Digits
Short 4
Short e 4 (Scientific Notation)
Long 15
{ P∙ e + x , : e + ( x )=10 x }
26
How to use MATLAB
Help, Lookfor
• Help: If you know the command but don't know how to operate it, you
can use the help command.
• Lookfor: This command can be used when you need general help rather
than help command.
Exam-
ple)
27
How to use MATLAB
General symbol
Type Digits
>> Prompt
A Transposed matrix of A
‘text’ Text string
[1, 3; 2, 4] Matrix
[1 , 3] Row vector
[1 ; 3] Column vector
A(1,2) Row 1, Column 2 – element of A
%A is the matrix Comments
A is the matrix; End of the line
t = 0:0.1:1 Start value: 0,
Final value: 1,
Interval between elements: 0.1
28
How to use MATLAB
Relational Operator & Logical Operator
(Relational)
(Logical)
• A & B: A and B
• A | B: A or B
• ~A: not A
29
How to use MATLAB
Vectors
• Variablename = [ ]
Example)
1. a = ,
2. b =
= [1.4142, 0.2857, 2.0000] ( a(1,2) is the 1st row - 2nd column element of ‘a’. )
• Also, you can make a matrix which is mixed with row or column vec-
tors.
Example) c = [b; a] =
30
How to use MATLAB
Vectors
• ':' is a symbol that extracts some elements of a vector.
Example)
a=
b=
c = a(2:3)
d = b(1:2)
e = [a(2:3) ; b(1:2)]
f = [c ; d]
31
How to use MATLAB
Vectors
Q) Then, How do you make a vector whose elements are listed in a
given rule?
𝛑 𝛑 𝛑 𝛑
𝟐 𝟐 𝟐 𝟐
32
How to use MATLAB
Vectors
• The other types of vector
33
How to use MATLAB
Vectors
• Calculation of vectors
34
How to use MATLAB
Vectors
• Example) How to draw a cosine function
35
How to use MATLAB
Vectors
• Example)
36
How to use MATLAB
Matrices
• How to make a matrix
37
How to use MATLAB
Matrices
• How to extract a matrix composed of elements in a matrix
38
How to use MATLAB
Matrices
• Calculation of some matrices
39
How to use MATLAB
Matrices
• Calculation of some matrices
40
How to use MATLAB
Matrices
• Calculation of some matrices
6. Invertible matrix
41
How to use MATLAB
Matrices
Example) Matrix Computation
42
How to use MATLAB
Matrices
• Elementwise multiplication
Example) Calculate when
43
How to use MATLAB
Matrices
• Special functions on matrices
It can make a
It can make a inverse matrix
zeros(m,n) m n matrix with inv(A)
of A.
all 0’s.
It can calculate
It can make a nn
eye(n) eig(A) an eigenvalue and an eigen-
identity matrix.
vector of a matrix A
44
How to use MATLAB
Matrices
Example)
45
How to use MATLAB
Matrices
[ ]
0 .1 1 1
0 0 .1 1
0 0 0.1
46
How to use MATLAB
☞ Exercise)
47
How to use MATLAB
☞ Exercise)
1)
48
How to use MATLAB
For, While
• For, While loop is used to perform the calculations of a formula sen-
tence over and over again.
• Structure
while( Condition ) ,
statement ;
end
49
How to use MATLAB
For loop
Example) Let’s make a 3 by 2 matrix.
Row loop
Column loop
50
How to use MATLAB
While loop
Example) Let’s calculate a sine function y =from 0 to .
51
How to use MATLAB
While loop
Exercise) Plot the cosine function y = ) A
52
How to use MATLAB
If loop
Exercise) Plot the unit step function at t = 2.
If ( Condition ) ,
Statement 1
else if (Condition)
Statement 2
else
Statement 3
end
53