matlab/simulink basics
TRANSCRIPT
MATLAB/Simulink MATLAB/Simulink Basics
Matlab 구조Command windowM editor: m fileM-editor: m-fileBasic commandsMathematical operatorsComplex number pi inf NaNComplex number, pi, inf, NaN, Who, clear, clear allMatrix operationsArray operationsArray operationsGraphicsFunctionOde solverOde so ve
Polynomials poly, conv, rootsTF d
Control functions: tf2ss, ss2tf, t
TF num, den
step
Basic math operator + - * / ^Basic math operator +, -, , /,
Case sensitive!
Matrix operation
Elementwise
<Creating a function>g
Polynomials
02337 23 =+−+ sss
solution>> roots([1 7 -3 23])
ans =
-7.7674 0 383 1 6 4i
0)6)(5)(2( =+++ sssConvert into polynomial
0.3837 + 1.6774i0.3837 - 1.6774i
0)6)(5)(( sssConvert into polynomial
>> poly([-2 -5 -6])
ans =
1 13 52 60
Polynomial multiplicationy p)1263)(9107( 23423 +++−+++ sssssss
>> conv([1 7 10 9],[1 -3 6 2 1])
ans =
1 4 5 23 48 81 28 91 4 -5 23 48 81 28 9
Convert the transfer function into state space representation
24)24269( 23 +++ sss
>> num=24;>> den=[1 9 26 24];
>> [A,B, C,D]=tf2ss(num, den)
>> [num,den]=ss2tf(A,B,C,D,1)
Time response τθθθ =++ cos2 mglbml &&&τ
θ
θ&=
=
2
1
xx
τθ
θ
+−−==
==
212
21
cos bxxLx
xx
&&&
&&
2 212 g
% Simulation of Inverted Pendulum% Simulation of Inverted Pendulum
t0 = 0;tf = 30;x0=[10*pi/180; 0];
function xdot=inv_pend_damped(t,x)
g=9.81;x0=[10*pi/180; 0];
%[t,x] = ode23('inv_pend', [t0:0.1:tf], x0);[t,x] = ode23('inv_pend_damped', [t0:0.1:tf], x0);
l= 1;b=1;
%define input u
figuresubplot(311)plot(t, x(:,1)*180/pi)grid
%u=0; %natural response%u=10; % unit step inputu=10* sin(5*t); %sine input
gridsubplot(312)plot(t, x(:,2)*180/pi)grid%phase plot
x1dot = x(2);x2dot = -g/l * cos(x(1)) - b*x(2) + u;
xdot =[x1dot; x2dot];%phase plotsubplot(313)plot(x(:,1)*180/pi, x(:,2)*180/pi)grid
Simulink basics
Time response of the system represented in transfer function
Time response of a system represented in state space form
>> figure>> plot(time_ss,y_ss)