Hello everyone, I want to define and solve a system of nonlinear equations in Simulink using the MATLAB Function block, but I encountered an error. I would like to ask, why is this happening?
Here is the code inside the MATLAB Function block:
Thank you for your reply, but the equations I want to implement are actually more complex and cannot be written in the form shown above. Here is the specific MATLAB FUNCTION Code:
Also, if possible, I would like to ask how to remove the display of "double" in the model. Even though I have turned off port data type display, "double" still appears.
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1. More information on function 'MATLAB Function' (#64.77.78), line 7, column 7: "2" Diagnostic report initiated.
Component: MATLAB Function | Category: Coder Error
Error parsing MATLAB function 'untitled/MATLAB Function'.
Component: MATLAB Function | Category: Coder Error
Due to errors in the module body or limitations of foundational analysis, Simulink cannot determine the output size and/or type of module 'untitled/MATLAB Function'. The error may not be accurate. Please fix the indicated errors or explicitly specify the size and/or type of all module outputs.
Component: MATLAB Function | Category: Coder Error
Due to errors in the module body or limitations of foundational analysis, Simulink cannot determine the output size and/or type of module 'untitled/MATLAB Function'. The error may not be accurate. Please fix the indicated errors or explicitly specify the size and/or type of all module outputs.
Component: Simulink | Category: Model Error
Error propagating data type 'double' through 'untitled/MATLAB Function'.
Then the error seems trivial. The integrator block has a 'Initial condition' property, which is by default set to 0, a scalar value. However your matlab function requires 2 inputs and has 2 outputs. So change the 'Initial condition' to be 'zeros(2,1)' and your code should run fine. For your actual problem, it seems like you have 5 states, so Initial condition:'' should be 'zeros(5,1)' instead.
You can also define initial condition to be different than 0 depending on the problem you wanna solve.
Hi @guo qing, Preliminary test shows that the dynamic equations look okay. Just make sure that the initial value for 5th state is non-zero, else you'll get a division-by-zero, leading to Inf or NaN reading.
The next step is to carry out the test in Simulink.
Thank you very much. I think the key to the problem lies in setting the initial value in the integrator module, just like you mentioned. As long as it is set, the problem is solved. However, it seems that when using block modular modeling, it is not necessary to set the initial value in the integrator module. This seems to be a unique aspect of the MATLAB Function block?
Thank you very much. I think the key to the problem lies in setting the initial value in the integrator module, just like you mentioned. As long as it is set, the problem is solved. However, it seems that when using block modular modeling, it is not necessary to set the initial value in the integrator module. This seems to be a unique aspect of the MATLAB Function block?
You are welcome, @guo qing. If you find the approach or solution helpful, please consider clicking 'Accept' ✔ on the Answer. Additionally, you can show your appreciation by voting 👍 for other helpful answers.
By the way, what do you mean by "block modular modeling"? If you use the S-Function block, then the Integrator block is unnessary. However, you will still need to supply the initial values in the code of the S-Function block. However, not many examples are provided for using the S-Function block to simulate the dynamic systems. Clicking the links directs users to other more links. 🤦♂️
Thank you very much. From my understanding, modular modeling refers to constructing a system using modules such as gain, product, and multiply, among others. In the systems built with these modules, it seems that Simulink can automatically determine the dimensions, and you only need to assign an initial value of 0 to the integrator module. Of course, the S-function you mentioned is also a good suggestion.
I understand that you want to solve a set of equations in Simulink and are encountering an error.
Without the knowledge of the exact error message, it will be difficult to the exact cause of the error encountered.
I recommend changing the "initial value" of the integrator function so that it gives exact result on the initial condition and does not cause any error. Here is the documentation to do so: https://www.mathworks.com/help/simulink/slref/integrator.html
By default, the initial value is set to 0 which may not be true depending upon the function being fed.
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1. More information on function 'MATLAB Function' (#64.77.78), line 7, column 7: "2" Diagnostic report initiated.
Component: MATLAB Function | Category: Coder Error
Error parsing MATLAB function 'untitled/MATLAB Function'.
Component: MATLAB Function | Category: Coder Error
Due to errors in the module body or limitations of foundational analysis, Simulink cannot determine the output size and/or type of module 'untitled/MATLAB Function'. The error may not be accurate. Please fix the indicated errors or explicitly specify the size and/or type of all module outputs.
Component: MATLAB Function | Category: Coder Error
Due to errors in the module body or limitations of foundational analysis, Simulink cannot determine the output size and/or type of module 'untitled/MATLAB Function'. The error may not be accurate. Please fix the indicated errors or explicitly specify the size and/or type of all module outputs.
Component: Simulink | Category: Model Error
Error propagating data type 'double' through 'untitled/MATLAB Function'.
Impossibile completare l'azione a causa delle modifiche apportate alla pagina. Ricarica la pagina per vedere lo stato aggiornato.
Translated by
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.