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

조회 수: 38 (최근 30일)
Joseph
Joseph 2024년 5월 10일
댓글: Joseph 2024년 5월 13일
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에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by