A matrix in symbolic mode will evaluate it in numeric mode
6 次查看(过去 30 天)
显示 更早的评论
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;
0 个评论
回答(1 个)
Divyam
2024-11-22,10:24
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!