Uploaded by 고경재

Matlab 2023

advertisement
MATLAB
MATLAB ?
n
n
Matrix Calculation Program for Matrix laboratory
Program language for science and engineering
calculation
n
Data
n
Simulation
MATLAB
Workspace
Folder
editor
Command
window
MATLAB files
n
*.mat
n
n
*.mdl
n
n
Save the Workspace
Save the Simulink
*.m
n
n
Save the Script
The file is used as an execution file
n
help ‘function name’
n
pwd
n
n
ls
n
n
Show the files in the current directory .
clear
n
n
Show the current directory.
Delete the variable in the memory
simulink
n
Excution Simulink
Matrix Operation
n
n
n
n
n
n
n
Representation of number
Definition of Matrix
Size
Transpose, Inverse matrix
Addition, Multiplication
Cross product, Dot product, Diagonal
Vector Generation
n
Real Number
n
n
n
9.6397
-1.301E-5
Imaginary number
n
n
1.0 + 2.1*i
3.4 - 4.1j
Definition and Extention
A=[1 2 3; 4 5 6; 7 8 9];
é1 2 3ù
ê
ú
A = ê4 5 6 ú
êë7 8 9úû
or
Þ
A=[1 2 3
456
7 8 9];
A1=[A;r];
[
]
r = 11 12 13
size(A1)
Þ ans =
4
3
Þ
Þ A1=[1
2
3
4
5
6
7
8
9
11 12 13];
A2=A1(1:3,:);
Þ A2=A
Matrix Transpose, Inverse
Addition and Multiplication
n
n
n
n
n
n
n
Transpose
Inverse
Addition
Multiplication
Cross Product
Dot Product
Diagonal
: AT = A’
: A-1 = inv(A)
: A+B, A-B
: A*B
: CROSS(A,B) for length 3
: DOT(A,B) for length 3
: diag(A)
Vector Generation
x=1:5
Þ ans =
1 2 3
x=1:0.1:1.4
4
5
Þ ans =
1.0
1.1
1.2
1.3
1.4
Plotting
n
plot
n
n
ezplot
n
n
Plot the Simple function
subplot
n
n
Plot the vaiable
Plot several graph simultaneous
plot3
n
3D plot
plot
Sine Wave
1
t=0:0.01:1;
0.8
0.6
plot(t,y),grid
0.4
xlabel('time(sec)')
ylabel('response')
title('Sine Wave')
response
y=sin(2*pi*5*t);
0.2
0
-0.2
-0.4
-0.6
plot(x, y, ’r*’)
hold on, hold off
figure(1), figure(2)
axis
-0.8
-1
0
0.2
0.4
0.6
time(sec)
0.8
1
subplot
? y=int('x*sin(x)');
? subplot(1,2,1);
? ezplot(y)
? subplot(1,2,2);
? ezplot(y+1)
plot3
? t = 0:pi/50:10*pi;
? plot3(sin(t),cos(t),t);
? grid
Þ
Function definition in m file
<stat.m>
function [stdeva] = stat(x)
n = length(x);
mean = sum(x) / n;
stdeva = sqrt(sum((x - mean).^2)/n);
A=[1 2 3 4];
stat(A)
ans =
1.11803398874989
주의 : function이름과 m파일의 파일명을 같게 한다.
for, while, if
for i=1:5:100
if condition
commands~
commands~
commands~
commands~
elseif condition
end
commands~
commands~
while condition
else
commands~
commands~
commands~
end
commands~
end
syms(‘x’); àsymbolic
deg2rad(); à degree àradian
hold on à hold the graph
Hold off à update new graph
grid on à generation of grid in the graph
x
x
1
2
z
H
z
1
x
0
z
0
θ
d
a
α
0-1
θ1
0
a1
0
1-H
θ2
0
a2
0
n
n
HW1-1 : 임의의 Transformation을 표현하는 4*4 행렬을 넣었을 때
Position vector를 얻어내는 Matlab 함수를 만드시오.
단, 함수명은 get_robot_pos(T) 로 만드시오.
HW1-2 : 임의의 Transformation을 표현하는 4*4 행렬을 넣었을 때
n,o,a vector를 얻어내는 Matlab 함수를 만드시오.
단, 함수명은 get_robot_orientation(T) 로 만드시오.
x
x
1
2
z
H
z
1
x
θ
d
a
α
0-1
θ1
0
90
0
1-H
θ2
0
70
0
0
z
0
HW2 : t=0~10
q1 =6t
q2=4.5t
L1 = 62cm, L2 =47cm
Plot Robot movement at each second
Print the x,y position at t second
(t is used as the final # of your student Number)
z
x2
z0
3
a2
y
x
x5
a3
2
4
x0
z1
HW3 : t=0~10
z2
z4
x1
1
a4
x3
z3
x4
z5
z6
x6
#
q
d
a
a
1
q1
0
0
90
2
q2
0
68
0
3
q3
0
56
0
4
q4
0
7
-90
- Plot Robot movement
5
- Print Final Position, n,o,a vector
- Print x,y,z position at t second
6
(t is used as the final # of your student Number
q5
0
0
90
q6
0
0
0
q1 =9t
q2=2t
q3=-t^2+3.5t
q4=2.2t
q5=0
q6=0
HW 4 : Matlab
z
x2
z0
3
a2
y
x
z2
z4
2
4
x0
z1
x5
a3
x1
1
a4
x3
z3
x4
z5
x6
#
q
d
a
a
1
q1
0
0
90
2
q2
0
64
0
3
q3
0
53
0
4
q4
0
8
-90
5
q5
0
0
90
6
q6
0
0
0
z6
HW : t=0~10
(3rd order Polynomial trajectory planning
t(0) : q1 =0, q2=0, q3=0, q4=0, q5=0, q6=0
t(10) : q1 =70, q2=30, q3=-40, q4=20, q5=0, q6=0
Figure 1 : Plot Robot movement (3D robot movement)
(Plot the robot position at each seconds)
Figure 2 : Plot 1~4 axis movement by using subplot (x axis : time, y axis : q)
Figure 3 : Plot position, velocity and Acceleration of 1-axis
(x axis : time, y axis : q, ω, α)
1. Folder name : Student #
à get_robot_pos.m, get_robot_orientation.m in that folder
à HW2.m, HW3.m, HW4.m in that folder
(It’s Ok to save additional functional file simultaneous at the folder)
2. Print only final results without other results.
3. The name of m file of HW2~HW4 is only allowed (HW2.m, HW3.m,
HW4.m)
4. Add the description at your own xxxx.m files
5. Program by yourself! (Don’t Copy, Don’t Cheating)
Download