Matlab Cheat Sheet PDF

Title Matlab Cheat Sheet
Course Automatic Control
Institution National Taiwan University
Pages 1
File Size 132.8 KB
File Type PDF
Total Downloads 58
Total Views 156

Summary

MATLAB...


Description

Matlab Function Cheat Sheet Clear Workspace

by Astra 07 Oct. 2019

Plot responses

>>clear; %clear all variables in workspace >>clc; %clear all commands in command window

>> figure(1);%Assign for first figure number >> step(sys);% Giving a step input >> grid on; % Grid the plot Output: Right click for more characteristic values

Create Input function Define timespan: >> t = 0:0.1:10; %10s time duration Define a step input: >>u = ones(size(t)); %Input length must be consistent with time

Overall transfer function with controller >> H = feedback(Gc*sys,1)% Controller trans. function >> figure(5); % Assign for the current figure number >> step(H); % Give a step input

Transfer Function Define a transfer function, for example only: sys =

s+1 s3 + s + 1

Find roots >> poles = roots(den);

(1)

>> num = [1,1] %num: coeffs of numerator, >> den = [1,3,1] %den: coeffs of denominator >> sys = tf([num],[den]) %Continuous-time transfer function. For a delay system, >> delay = 1 %:delay 1 second. >> sys = tf([num],[den],’InputDelay’,delay) Another way to set up transfer function: >> s = tf(’s’) >> sys = (s+1)/(s3 + 3 ∗ s + 1) Convert state-space equation to transfer function: >> [num,den] = ss2tf(A,B,C,D) >> sys2 = tf([num,den]) State-space Equation Convert transfer function to state-space equation: >> [A,B,C,D] = tf2ss([num],[den]) >> sys2 = ss(A,B,C,D) For a delay system, >> sys2 = ss(A,B,C,D,’InputDelay’,delay) Alternatively, T (s) = C(sI − A)−1 B + D, >> sys2 = C*(inv(s*eye(2)-A)*B)+D % eye() stands for identity matrix

PID control >> Kp = 1; >> Ki = 1; >> Kd = 1; >> Gc = pid(Kp, Ki, Kd)% Controller trans. function Look for ’Incremental Value and Run section’ for tuning technique!

Pole-Zero Map >>[p, z] = pzmap(H); % Pole-zero map Try >> >> >>

yourself: figure(2);%Assign for the figure number impulse(sys);% Giving a step input grid on; % Grid the plot

Linear Simulation Simulate time response of dynamic systems to arbitrary inputs >> X0=[0;1]; % Initial conditions if needed, dimension must meet! >> figure(3); % Assign for the current figure number >> lsim(sys,u,t,X0); >> grid on; % Grid the plot Homogeneous Response Simulate time response of dynamic systems to arbitrary inputs >> X0=[0;1]; % Initial conditions if needed, dimension must meet! >> figure(4); % Assign for the current figure number >> initial(sys,X0); >> grid on; % Grid the plot

Complex Numbers In main program, >>global m c k Define arbitrary value for m,c,k. >>[t y] = ode45(’solve_ode’, t, X0); >>figure(6); >>plot(t, y(:,1)); grid on; >>title(’The numerical result by ode45 function’); >>xlabel(’t- time’); ylabel(’x- position’); >>legend(’x1’,’x2’); In sub-program, save another .m file called exactly as the function name (solve_ode.m) at the same path. function dy=solve_ode(t,y)%subprogram for ode global m c k dy=[0;0]; %Set the starting points from 0 dy(1)= y(2); dy(2)=-k./m*y(2)-c./m*y(1)+ ones(size(t)); end...


Similar Free PDFs