mphstate
Get state-space matrices for a dynamic system.
Syntax
str = mphstate(model,soltag,'Out',{'SP'})
str = mphstate(model,soltag,'Out',{'SP1','SP2',...})
Description
str = mphstate(model,soltag,'out',{'SP'}) returns a MATLAB® structure str containing the state-space matrix SP assembled using the solver node soltag and accessible as str.SP, SP being taken from the Out property list.
str = mphstate(model,soltag,'out',{'SP1','SP2',...}) returns a MATLAB structure str containing the state-space matrices SP1, SP2, ... assembled using the solver node soltag and accessible as str.SP1and str.SP2. SP1 and SP2 being taken from the out property list.
The function mphstate accepts the following property/value pairs:
MA | MB | A | B | C | D | Mc | Null | ud | x0
off | on
off | on
init | sol
soltag | zero
The property Sparse controls whether the matrices A, B, C, D, M, MA, MB, and Null are stored in the sparse format.
The equations correspond to the system below:
where x are the state variables, u are the input variables, and y are the output variables.
A static linearized model of the system can be described by:
The full solution vector U can be then obtained from
where Null is the null-space matrix, ud the constraint contribution, and u0 is the linearization point, which is the solution stored in the sequence once the state-space export feature is run.
The matrices MC and MCA are produced by the same algorithms that do the finite-element assembly and constraint elimination in COMSOL Multiphysics. MC and MCA are the same as the matrices DC (eliminated mass matrix) and KC (KC is the eliminated stiffness matrix). The matrices are produced from an exact residual vector Jacobian calculation (that is, differentiation of the residual vector with respect to the degrees of freedoms x) plus an algebraic elimination of the constraints. The matrix C is produced in a similar way (that is, the exact output vector Jacobian matrix plus constraint elimination).
The matrices MCB and D are produced by a numerical differentiation of the residual and output vectors, respectively, with respect to the input parameters (the algorithm systematically perturbs the input parameters by multiplying them by a factor 1+108).
The input cannot be a variable constraint in the model.
Example
Load model_tutorial_llmatlab.mph:
model = mphopen('model_tutorial_llmatlab');
comp1 = model.component('comp1');
comp1.mesh('mesh1').autoMeshSize(9);
std = model.study.create('std');
time = std.feature.create('time','Transient');
time.set('tlist','range(0,1,50)');
Edit the model to use parameter for the initial and external temperature:
model.param.set('T0','293.15[K]');
model.param.set('Text','300[K]');
ht = model.component('comp1').physics('ht');
ht.feature('init1').set('Tinit', 'T0');
ht.feature('hf1').set('Text', 'Text');
Add a domain point probe plot:
pdom = comp1.probe.create('pdom', 'DomainPoint');
pdom.model('comp1');
pdom.set('coords3',[0 0 1.1e-2]);
Run the study and create a plot group to display the probe:
std.run;
pg1 = model.result.create('pg1', 'PlotGroup1D');
glob1 = pg1.create('glob1', 'Global');
glob1.setIndex('expr', 'comp1.ppb1', 0);
Extract the state-space system matrices of the model with power, Temp, and Text as input and the probe evaluation comp1.ppb1 as output:
M = mphstate(model,'sol1','out',{'A','B','C','D'},...
'input',{'power','Temp','Text'},'output','comp1.ppb1');
Plot the sparsity of the matrix A:
subplot(1,2,1); spy(M.A); subplot(1,2,2); spy(abs(M.A)>1e-2)
Set the input power parameter and the reference temperature:
power = 30; Temp = 300; Text = 300; T0 = 293.15;
Compute the system solution:
input = [power Temp-T0 Text-T0];
func = @(t,x) M.A*x + M.B*input';
[t,x] = ode45(func,0:1:50,zeros(size(M.A,1),1));
y = M.C*x';
y = y+T0;
Plot the result:
plot(t,y,'r');
hold on;
mphplot(model,'pg1');
Evaluate the steady-state temperature value:
G = M.D-M.C*(inv(M.A))*M.B;
y_inf = full(G*input');
y_inf = y + T0