A matrix in symbolic mode will evaluate it in numeric mode

6 Ansichten (letzte 30 Tage)
JuanMa
JuanMa am 17 Mär. 2023
Beantwortet: Divyam am 22 Nov. 2024 um 10:24
Dear
A matrix of a dynamic system, with the symbolic mode, could be discretized with the ZOH method. I want the symbolic components of the discretized matrix, evaluate them and as a result obtain the matrix with the numerical values in order to later simulate the response of the dynamic system.
I attach the code.
Thank you
JuanMa
clear;
syms CinvS LinvS TinvS
A = [0, -1/LinvS; 1/CinvS, 0]
Ad = expm(TinvS * A)
Ai = [0, -1/LinvS; 1/CinvS, 0]
Bi = [1/LinvS; 0]
Bo = [0; -1/CinvS]
Ms = [Ai, Bi, Bo; 0, 0, 0, 0; 0, 0, 0, 0]
Mds = expm(Ms * TinvS)
% Parameters
Linv = 621.26e-6;
Cinv = 10e-6;
Tinv = 50e-6;

Antworten (1)

Divyam
Divyam am 22 Nov. 2024 um 10:24
Hi @JuanMa,
The "subs" function can be used to substitute the numeric values in the discretized matrices and the "double" function from the Symbolic Math Toolbox can be used to convert the symbolic values to MATLAB double precision.
clear;
syms CinvS LinvS TinvS
A = [0, -1/LinvS; 1/CinvS, 0];
Ad = expm(TinvS * A);
Ai = [0, -1/LinvS; 1/CinvS, 0];
Bi = [1/LinvS; 0];
Bo = [0; -1/CinvS];
Ms = [Ai, Bi, Bo; 0, 0, 0, 0; 0, 0, 0, 0];
Mds = expm(Ms * TinvS);
% Parameters
Linv = 621.26e-6;
Cinv = 10e-6;
Tinv = 50e-6;
% Substitute numerical values into the discretized matrices
Ad_numeric = subs(Ad, {LinvS, CinvS, TinvS}, {Linv, Cinv, Tinv});
Mds_numeric = subs(Mds, {LinvS, CinvS, TinvS}, {Linv, Cinv, Tinv});
% Evaluate the symbolic expressions to obtain numerical matrices
Ad_numeric = double(Ad_numeric);
Mds_numeric = double(Mds_numeric);
% Display the class of each matrix to confirm successful conversion
fprintf('The type of matrix Ad is: %s\n', class(Ad));
fprintf('The type of matrix Ad_numeric is: %s\n', class(Ad_numeric));
fprintf('The type of matrix Mds is: %s\n', class(Mds));
fprintf('The type of matrix Mds_numeric is: %s\n', class(Mds_numeric));
For more information regarding the "subs" function, refer to this documentation: https://www.mathworks.com/help/symbolic/sym.subs.html
For more information regarding the "double" function, refer to this documentation: https://www.mathworks.com/help/symbolic/sym.double.html

Produkte


Version

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by