Error: The "A" matrix must be a numeric array with no Inf's or NaN's.
42 次查看(过去 30 天)
显示 更早的评论
coder.extrinsic("testcon2dis")
I_2 = eye(2);
O_2 = zeros(2);
Ac_xy = [O_2 -(1/Lfilter)*I_2 O_2; (1/Cfilter)*I_2 O_2 -(1/Cfilter)*I_2; O_2 O_2 w* J];
Bc_xy = [(Vdc/Lfilter)*I_2 O_2 O_2]' * Tr;
Cxy = [I_2 O_2 O_2; O_2 I_2 O_2];
[A, B] = testcon2dis(Ac_xy, Bc_xy, Cxy, Ts);
%%%%%%%%%%%%%%%% Below is the testcon2dis%%%%%%%%%%%%%%%%
function[A,B] = testcon2dis(Ac_xy,Bc_xy,Cxy,Ts)
ct_sys = ss(Ac_xy,Bc_xy,Cxy,[]);
dt_sys = c2d(ct_sys,Ts);
A = dt_sys.a;
B = dt_sys.b;
end
%%%%%%%%%%%%%%%%%%%%%%% Error message
Error:The "A" matrix must be a numeric array with no Inf's or NaN's.
Error in ss.ss.m (line 290)
throw(ME)
Error in testcon2dis.m (line 2)
Error in 'MPC_3Phase_Inverter/MATLAB Function1' (line 31)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Any suggestions I tried calling the A marix as a double or zeros to give it sizes but still got new errors doesn't work(this block of code is used in a matlab function block simulink)
%%%%%%%%%%%%%%%%%%%%% Error message calling A as a double or zeros(6,6)%%%%%%%%%%%%%%%
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN.
> In MPC_Matrices_l (line 69)
Error:Matrix must be positive definite.
Error in MPC_Matrices_l.m (line 70)
Hinv=chol(W_inv);
Error in 'MPC_3Phase_Inverter/MATLAB Function1' (line 43)
Any suggestions thank you
4 个评论
Sam Chak
2024-5-11
编辑:Sam Chak
2024-5-11
Code looks okay. Check other parameters that are not shown.
%% parameters
I_2 = eye(2);
O_2 = zeros(2);
Lfilter = 1; % not shown
Cfilter = 1; % not shown
w = 1; % not shown
J = eye(2); % not shown
Tr = 1; % not shown
Vdc = 1; % not shown
%% state-space matrices
Ac_xy = [O_2 -(1/Lfilter)*I_2 O_2; (1/Cfilter)*I_2 O_2 -(1/Cfilter)*I_2; O_2 O_2 w* J];
Bc_xy = [(Vdc/Lfilter)*I_2 O_2 O_2]'*Tr;
Cxy = [I_2 O_2 O_2; O_2 I_2 O_2];
Ts = 0.1;
%% Test function
[A, B] = testcon2dis(Ac_xy, Bc_xy, Cxy, Ts)
function [A, B] = testcon2dis(Ac_xy, Bc_xy, Cxy, Ts)
ct_sys = ss(Ac_xy,Bc_xy,Cxy,[]);
dt_sys = c2d(ct_sys,Ts);
A = dt_sys.a;
B = dt_sys.b;
end
采纳的回答
Kalhara
2024-5-12
% Check for NaNs
any(isnan(A(:)))
% Check for infinite values
any(isinf(A(:)))
A(isnan(A)) = 0; % Replace NaNs with zeros
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!