(1) margin function: Calculate amplitude margin and phase angle margin and corresponding turning frequency
Margin (mag,phase,w): The amplitude of mag (not in db), phase angle phase, and angular frequency w vectors obtained by the bode instruction are plotted with a bode graph with headroom and corresponding frequency display.
Margin (Num,den): Calculates the amplitude margin and phase angle margin of the continuous system transfer function representation and plots the corresponding baud plot. Similarly, margin (a,b,c,d) calculates the amplitude margin and phase angle margin represented by the continuous state space system and plots the corresponding baud plot.
[Gm,pm,wcg,wcp]=margin (MAG,PHASE,W): From the amplitude of mag (not in db), phase angle phase and angular frequency w vector calculation of the system amplitude margin and phase angle margin and the corresponding phase angle junction frequency WCG, cutoff frequency WCP, Instead of drawing the Bode curve directly.
Note: When VC (or MFC) calls MATLAB, the margin function cannot be used in M files, it should be a symbol used in the margin function.
Note two: M files cannot define special symbols, such as "S=TF (' s ')", because MFC does not recognize these symbols.
Note Three: When you use the margin function, the following colors and linetypes are not set by yourself, and these are the settings that you can use for these functions like Step,bode.
(2) Multi-curve marking
MATLAB provides a number of drawing options to determine the Linetype, color, and data point marker symbols for the plotted curve. These options are as shown in the table:
Linear |
Color |
Marker symbols |
-Solid Line |
b Blue |
. Point |
s block |
: Dashed |
G Green |
O Circle |
D Diamond |
-. Dot Dash |
R Red |
X Fork Number |
∨ downward triangle symbol |
--Double Dash |
C Cyan |
+ Plus |
∧-Up triangle symbol |
|
M Magenta |
* Asterisk |
< left triangle symbol |
|
Y Yellow |
|
> north-Right triangle symbol |
|
K Black |
|
P-Pentagram |
|
W White |
|
H Hex Star |
(3) Graphic annotation
When you draw a drawing, you can add a description to the graphic, such as the name of the graphic, the axis description, and the meaning of a part of the graphic, called adding a graphic callout. The calling format for the graphical callout function is:
Title (' Graphic name ') (enclosed in single quotes)
Xlabel (' X-axis description ')
Ylabel (' Y-axis description ')
Text (x, y, ' graphics description ')
Legend (' Fig. 1 ', ' fig. 2 ', ... ) (4) grid on: Display Grid when drawing
(5) Spline function: Draw point drawing, drawing discrete curve
Cases:
X=[0 1 2 3 4 5 6 7 8 8.85];y=[13 12.1 11 10.5 10.1 9.9 9.6 9.3 9.0 8.9];
Xx=0:0.01:10;
Yy=spline (X,Y,XX);
Plot (x, y, ' o ', xx,yy)
(6) Conv () function
The explanation of help in MATLAB is:
CONV convolution and polynomial multiplication.
C = CONV (A, B) convolves vectors A and B. The resulting vector is
Length MAX ([Length (a) +length (b) -1,length (a), length (b)]). If A and B are
Vectors of polynomial coefficients, convolving them is equivalent to
Multiplying the polynomials.
C = CONV (A, B, SHAPE) returns a subsection of the convolution with size
specified by SHAPE:
"Full"-(default) returns the full convolution,
' Same '-returns the central part of the convolution
That's the same size as A.
' Valid '-returns only those parts of the convolution
That is computed without the zero-padded edges.
Length (C) is MAX (length (A)-max (0,length (B)-1), 0).
Class support for inputs A, B:
Float:double, single
Examples of this project: The following is the M file, the implementation of the control object parameters and controller parameters to draw the system Bode diagram function
function bodeofchecked (WN,ZETA,KP,TI,TD)
%num0=wn^2;
%den0=conv ([1,0],[1 2*wn*zeta wn^2]);
%G0=TF (Num0,den0);
Num=conv ([0 wn^2],conv ([0 kp],[ti*td ti 1]));
Den=conv ([1 0],conv ([1 2*wn*zeta wn^2],conv ([0 1],[ti 0]));
%GC=TF (NUM1,DEN1);
Bode (Num,den); grid on;
End
(7) Programming Basics
①if
Single branch:
An IF condition expression
Statement Group
End Dual Branch:
An IF condition expression
Statement Group 1
Else
Statement Group 2
End Multi-branch:
If condition expression 1
Statement Group 1
ElseIf conditional Expression 2
Statement Group 2
... ...
ElseIf conditional Expression M
Statement Group M
Else
Statement Group
End②switch
Switch expression
Case Expression 1
Statement Group 1
Case Expression 2
Statement Group 2
... ...
Case Expression M
Statement Group M
otherwise
Statement Group
End③for Cycle
For loop variable = List of values
Loop body
End example: clear;
y=0; n=100;
For K=1:n
y=y+1/(2*k-1);
End
④while
While-conditional expression
Loop body
End Example:
While 1
N=input (' Please enter n (nonpositive quit): ');
If n<=0, break; End
NT = n; % records the initial value of n
Whilen>1
If mod (n,2) ==0
n = N/2;
Else
n = 3*n+1;
End
fprintf (' n=%d \ n ');
End
fprintf (' n=%d is not we need! \ n ', NT);
End