📄 calcdemo.m
字号:
% CALCDEMO Demonstration of Basic Functions in the MFD TOOLBOX.
echo off
% J.M. Boyle 30th August 1987
% Copyright (c) 1987 by GEC Engineering Research Centre & Cambridge Control Ltd
% History:
% Minor layout changes made, 12.7.93, JMM.
% MRN0007, MRN0016, MRN0023, MRN0036
if exist('genrdata.mat') ~= 2, % If data file does not exist ...
disp(' Generating data for demonstration')
genrprep; % ... then generate it.
end
load genrdata
w=ws;
mvfr = mvfrs;
clc
echo on
% Basic Functions in the Multivariable Frequency Domain Toolbox.
% ===============================================================
% This demo introduces some of the basic functions that are
% available in the Multivariable Frequency Domain Toolbox.
% All the functions operate on Multi-Variable Frequency Response
% (MVFR) matrices.
% Ways in which an MVFR matrix can be formed are covered in the demo:
% 'Generating and Displaying an MVFR matrix'.
% The MVFR matrix generated during that demo is reused here.
% Remember that the MVFR matrix represents an open loop unstable
% chemical reactor.
% To refresh your memory, here are the component matrices of the
% compressed MVFR matrix.
pause % Strike any key to display MVFR matrix.
clc
fdisp(w,mvfr)
pause % Strike any key to continue.
clc
% Now let's look at how to pick out parts of a frequency response matrix.
% To pick out a single component matrix we can use FGETF(W,F,INDEX).
% INDEX is a vector which specifies which component matrices are to
% be picked out. To return the second component matrix, INDEX = 2:
[f2,w2] = fgetf(w,mvfr,2)
pause % Strike any key to continue.
clc
% To pick out elements of component matrices we can use FGET(W,F,INDEX).
% INDEX is a two column matrix whose rows specify the elements to be
% picked out. To pick out the frequency response of the (1,1) element:
f = fget(w,mvfr,[1,1])
pause % Strike any key to continue.
% If you use FGET to pick out elements of a component matrix and then
% modify those elements in some way, you can use
% FPUT(W,F,ELEMENTS,INDEX) to put back the elements.
% The columns of ELEMENTS contain the elements to be 'put' and
% INDEX specifies the positions in the component matrices where
% the elements are to be 'put'.
pause % Strike any key to continue.
clc
% Let's put the [1,1] element we picked out using FGET back into
% the [2,2] position.
ftemp = fput(w,mvfr,f,[2,2]);
pause % Strike any key to display the resulting MVFR matrix.
clc
fdisp(w,ftemp)
pause % Strike any key to continue.
clc
% To extract the diagonal elements of component matrices, use
% FDIAG(W,F).
fd = fdiag(w,ftemp);
% Strike any key to display the diagonal elements.
% These should be the same, because we copied the [1,1] element to
% the [2,2] position.
pause
fdisp(w,fd)
% FDIAG can also be used to generate diagonal MVFR matrices.
pause % Strike any key to continue.
clc
% Combining MVFR Matrices.
% ========================
% There is a set of functions that allow MVFR matrices to be combined.
% Addition.
% ---------
% FADD(W,F,C) adds the matrix C to each component matrix of F.
% Firstly, we must make up an arbitrary C matrix.
c = [100 0;0 -100]
ftemp = fadd(w,mvfr,c);
pause % Strike any key to display the resulting matrix.
fdisp(w,ftemp)
pause % Strike any key to continue.
clc
% FADDF(W,F1,F2) adds two MVFR matrices
% In this example we will add one MVFR matrix to itself.
ftemp = faddf(w,mvfr,mvfr);
pause % Strike any key to display the resulting matrix.
fdisp(w,ftemp)
pause % Strike any key to continue.
clc
% Multiplication.
% ---------------
% FMUL(W,F,C) multiplies each component matrix of F by C.
ftemp = fmul(w,mvfr,c);
pause % Strike any key to display the resulting matrix.
fdisp(w,ftemp)
pause % Strike any key to continue.
clc
% FMULF(W,F1,F2) multiplies two MVFR matrices.
% Take care with the order in which you specify F1 and F2.
ftemp = fmulf(w,mvfr,mvfr);
pause % Strike any key to display the resulting matrix.
fdisp(w,ftemp)
pause % Strike any key to continue.
clc
% Basic Mathematical Operations on a MVFR Matrix.
% ===============================================
% We shall now look at some of the mathematical operations which
% may be performed on a MVFR matrix.
% Calculating Eigenvalues.
% ------------------------
% The eigenvalues of an MVFR matrix are calculated using
% FEIG(W,F)
eigval = feig(w,mvfr);
pause % Strike any key to display the eigenvalues.
fdisp(w,eigval)
pause % Strike any key to continue.
clc
% Calculating Singular Values.
% ----------------------------
% The singular values of an MVFR matrix are calculated using the
% function FSVD(W,F).
sval = fsvd(w,mvfr);
pause % Strike any key to display the singular values.
fdisp(w,sval)
pause % Strike any key to continue.
clc
% Inverting an MVFR matrix.
% -------------------------
% FINV inverts the component matrices of an MVFR matrix.
ftemp = finv(w,mvfr);
fident = fmulf(w,mvfr,ftemp);
% Strike any key to display results
% of the MVFR matrix multipled by its inverse
pause
clc
fdisp(w,fident)
pause % Strike any key to continue.
clc
% Complex Conjugate Transpose of a MVFR matrix.
% ---------------------------------------------
% FTRN transposes the component matrices of a MVFR matrix.
mtrn = ftrn(w,mvfr);
pause % Strike any key to display results.
fdisp(w,mtrn)
pause % Strike any key to continue.
clc
% In fact, we have developed a function FFUN(W,F,'FUN'), that
% allows us to execute a function on each component matrix of
% an MVFR matrix. The parameter 'FUN' specifies which function
% is to be executed. It can be either a resident MATLAB function
% or one you have written yourself. The function must accept a
% single matrix argument and return a single result (scalar,
% vector or matrix). For example, we can call the SRQT function:
msqrt = ffun(w,mvfr,'sqrt');
pause % Strike any key to display the results.
fdisp(w,msqrt)
pause % Strike any key to return to the Main Menu.
echo off
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -