Index exceeds the number of array elements
Show older comments
I am doing normal simulink for a cricuit includes normal elements like mosfet,capacitor, inductor and transformer whaen I run the circuit i received this ereor:-
Warning: Matrix is singular to working precision.
Index exceeds the number of array elements. Index must not exceed 0.
Component:Simulink | Category:Model error
can anyone help pls.
thanks
5 Comments
dpb
on 14 Aug 2022
I "know nurhink!" about Simulink so can't speak of anything that might be specific to it's use, but those would appear to be to separate issues -- of course, the first is a Warning while the second is error...
The first means for whatever model is trying to be solved by whatever tool, the problem matrix has two columns/independent variables that are linearly related -- one is close-enough to another such as to be nearly its multiple. This means you have not enough independent variables to uniquely solve for the desired number of variables.
The second is a problem -- somewhere you've defined a variable as the result of an operation (FIND()) is a good an often-found candidate) which returned an empty result for its search and that result was then used to allocate or reference an array...note the reference ot the fact the allowable array size/index is 0 -- that's a reference to an empty variable.
Would have to see the code as well to have any idea what actually is going on, but those are things to look for...
SALAH alatai
on 14 Aug 2022
dpb
on 14 Aug 2022
Well, your model reduces down to a linear combination of variables then -- and somewhere there's an empty object.
I've never even seen a Simulink installation, so I've no idea how one could have constructed such nor how to know where the isse lies, but those are the things that would cause such symptoms/errors numerically.
SALAH alatai
on 18 Aug 2022
Steven Lord
on 18 Aug 2022
Without seeing your Simulink model it's going to difficult if not impossible to offer any concrete suggestions for how to avoid this error.
Answers (1)
Shivani Dixit
on 26 Aug 2022
Hello,
I understand that you get the error “Matrix is singular to working precision“ while executing your Simulink model.
The following could be the cause of the issue:
- A major possibility is that you have encountered a roundoff error that demonstrates a fundamental problem with the way computers deal with numbers of vast differences in magnitude.
Since the machine uses a finite number of bits to represent any number (in MATLAB's case, 64 bits are used), matrices that are poorly scaled are difficult to work with. One way to visualize the problem is using a 2-dimensional system. As an example, consider “A” as a simple non-singular matrix:
>> A = [1 0 ; 0 1];
The two column vectors in this matrix are as linearly independent as possible. However, if we stretch one vector and shrink the other, the matrix becomes closer to [k 0; 0 0], which is singular.For the smaller number, some precision is lost because the computer has difficulty representing both numbers with the same amount of accuracy.
>> format long
>> A=[2^50 0;0 2^(-50)]
A =
1.0e+015 *
1.12589990684262 0
0 0.00000000000000
Note that, although the machine could represent 2^(-50) by itself, it has lost the number's true value here, because it needs to deal with larger numbers at the same time.
So, even if this matrix is still non-singular in the true world of mathematics, it is singular to working precision on the computer, and singular matrices can cause the same kinds of problems that division by zero causes.
2 Comments
SALAH alatai
on 28 Aug 2022
Shivani Dixit
on 1 Sep 2022
Hello,
The answer above mentions a possible situation that your model must have encountered.
I suggest you the following workarounds:
- You must check for the inputs (matrices, vectors if any), output or any data being fed to your model that may cause this issue in your model as mentioned above. If such a data exists, please try the following workaround:
As mentioned above, for smaller numbers, some precision may be lost because the computer has difficulty representing both numbers with the same amount of accuracy, example:
>> format long
>> A = [2^50 0;0 2^(-50)]
If you find data similar to this, try using the symbolic toolbox:
>> format long
>> A=[sym(2^50) 0 ; 0 sym((2^(-50)))]
This would help you resolve this issue. There are several other tools that you can take help of when dealing with large numbers, for more information you can refer to the following answer:
If the above workaround does not work, please check whether you get same warning message in other standard models. If not, please share a dummy model which is similar to your current model so that I can reproduce the issue on my end and help you better.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!