Error: The "A" matrix must be a numeric array with no Inf's or NaN's.

15 次查看(过去 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
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)
A = 6x6
0.9950 0 -0.0998 0 0.0052 0 0 0.9950 0 -0.0998 0 0.0052 0.0998 0 0.9950 0 -0.1050 0 0 0.0998 0 0.9950 0 -0.1050 0 0 0 0 1.1052 0 0 0 0 0 0 1.1052
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
B = 6x2
0.0998 0 0 0.0998 0.0050 0 0 0.0050 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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
Joseph
Joseph 2024-5-13
Thank your the comment, I realise the error message genrated by the matlab didnt point exactly to the error. I realise the issue is with the AC_xy matrix which from the other sugegstion I was told to use the isany nan command to resolve it.

请先登录,再进行评论。

采纳的回答

Kalhara
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 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by