Make Error in Simulink – Division by Zero?
Mostrar comentarios más antiguos
I looked up Make Errors here, and most of the issues were solved by calling 'mex -setup'. I gave that a shot, and everything looked fine. I'm using MATLAB R2011a Student Version along with its built-in lcc C Compiler.
My Simulink model consists of two MATLAB functions, some constants and 'From Workspace' sources. One of the MATLAB functions is 154 lines long and includes four extrinsic functions, all of which are declared as such at the beginning of the function. The other is basically a placeholder and passes the outputs as the same as inputs.
Here are the errors, buried in a long error report:
Error c2_cogen2_simulink.c: 5380 Division by zero
Error c2_cogen2_simulink.c: 5383 Division by zero
Error c2_cogen2_simulink.c: 5411 Division by zero
Here's the full error report, in case it sheds more light on the issue:
Making simulation target "cogen2_simulink_sfun", ...
C:\Users\Zack\Documents\Italy Research\cogen1\slprj\_sfprj\cogen2_simulink\_self\sfun\src>"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lccmake" -f cogen2_simulink_sfun.lmk
Warning c1_cogen2_simulink.c: 482 static `void function(pointer to void,pointer to const incomplete struct mxArray_tag defined at C:\Program Files (x86)\MATLAB\R2011a Student\extern\include\matrix.h 298,pointer to const char,pointer to void) c1_c_sf_marshallIn' is not referenced
Warning c1_cogen2_simulink.c: 455 static `pointer to const incomplete struct mxArray_tag defined at C:\Program Files (x86)\MATLAB\R2011a Student\extern\include\matrix.h 298 function(pointer to void,pointer to void) c1_c_sf_marshallOut' is not referenced
0 errors, 2 warnings
Error c2_cogen2_simulink.c: 5380 Division by zero
Error c2_cogen2_simulink.c: 5383 Division by zero
Error c2_cogen2_simulink.c: 5411 Division by zero
Warning c2_cogen2_simulink.c: 6780 static `void function(pointer to void,pointer to const incomplete struct mxArray_tag defined at C:\Program Files (x86)\MATLAB\R2011a Student\extern\include\matrix.h 298,pointer to const char,pointer to void) c2_u_sf_marshallIn' is not referenced
Warning c2_cogen2_simulink.c: 6753 static `pointer to const incomplete struct mxArray_tag defined at C:\Program Files (x86)\MATLAB\R2011a Student\extern\include\matrix.h 298 function(pointer to void,pointer to void) c2_u_sf_marshallOut' is not referenced
Warning c2_cogen2_simulink.c: 6671 static `double function(pointer to SFc2_cogen2_simulinkInstanceStruct,double) c2_sign' is not referenced
Warning c2_cogen2_simulink.c: 6570 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,int,double,int,int,pointer to double,int,int,pointer to double,pointer to int,int,int,pointer to double,pointer to int) c2_ceval_xger' is not referenced
Warning c2_cogen2_simulink.c: 6524 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,int,double,pointer to double,pointer to int,int,int,pointer to double,pointer to int,int,int,double,pointer to double,int,int,pointer to double) c2_ceval_xgemv' is not referenced
Warning c2_cogen2_simulink.c: 6480 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,int,pointer to double,pointer to int,int,int,pointer to double,pointer to int,int,pointer to double,pointer to double) c2_eml_blas_xgemv' is not referenced
Warning c2_cogen2_simulink.c: 6452 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,int,int,double,pointer to double,pointer to int,int,int,pointer to double,pointer to double,pointer to int,pointer to double) c2_eml_matlab_zlarf' is not referenced
Warning c2_cogen2_simulink.c: 6443 static `double function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,double,double,int,int) c2_b_ceval_xscal' is not referenced
Warning c2_cogen2_simulink.c: 6434 static `double function(pointer to SFc2_cogen2_simulinkInstanceStruct,double,double) c2_b_eml_xscal' is not referenced
Warning c2_cogen2_simulink.c: 6425 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,double,double,pointer to double,pointer to double,pointer to double) c2_b_eml_matlab_zlarfg' is not referenced
Warning c2_cogen2_simulink.c: 6403 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,double,pointer to double,pointer to int,int,int,pointer to double,pointer to int) c2_ceval_xscal' is not referenced
Warning c2_cogen2_simulink.c: 6383 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,double,pointer to double,pointer to int,int,pointer to double,pointer to int) c2_eml_xscal' is not referenced
Warning c2_cogen2_simulink.c: 6331 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,double,pointer to double,pointer to int,int,pointer to double,pointer to double,pointer to int,pointer to double) c2_eml_matlab_zlarfg' is not referenced
Warning c2_cogen2_simulink.c: 6309 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,pointer to double,pointer to int,int,int,int,int,pointer to double,pointer to int) c2_ceval_xswap' is not referenced
Warning c2_cogen2_simulink.c: 6287 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,pointer to double,pointer to int,int,int,int,int,pointer to double,pointer to int) c2_eml_refblas_xswap' is not referenced
Warning c2_cogen2_simulink.c: 6265 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,pointer to double,pointer to int,int,int,int,int,pointer to double,pointer to int) c2_eml_blas_xswap' is not referenced
Warning c2_cogen2_simulink.c: 6245 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,pointer to double,pointer to int,int,int,pointer to double,pointer to int) c2_eml_xswap' is not referenced
3 errors, 17 warnings
"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\extern\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\simulink\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\mex\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\debugger\include" "cogen2_simulink_sfun.c"
"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\extern\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\simulink\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\mex\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\debugger\include" "cogen2_simulink_sfun_registry.c"
"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\extern\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\simulink\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\mex\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\debugger\include" "c1_cogen2_simulink.c"
"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\extern\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\simulink\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\mex\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\debugger\include" "c2_cogen2_simulink.c"
C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lccmake: Error code 1
Thanks for any help you can give.
Zack
Respuesta aceptada
Más respuestas (2)
Fangjun Jiang
el 23 de Nov. de 2011
I assume you understand what is division by zero error. Every time you do a division, in C or in MATLAB, the safest way is to check whether the denominator is zero.
if abs(b)<eps
% do something, such as assign b or c to a fixed number
else
c=a/b;
end
So check the code in your MATLAB function to see if you have such operation and if you have the safeguard.
In Simulink, you can turn on the diagnositcs. Under menu Simulation->Configuration Parameters...->Diagnostics-> Data validity, turn on the check for "Signal"->"Inf or NaN block output". So when you run simulation, hopefully it can help you find out these division by zero errors early on so you don't have to deal with it until generating code and compiling it.
6 comentarios
Kaustubha Govind
el 23 de Nov. de 2011
You beat me to it, Fangjun. :)
@Zachary: Please also follow Fangjun's advice to verify if the problem isn't indeed with your code.
Zachary Santer
el 23 de Nov. de 2011
Fangjun Jiang
el 23 de Nov. de 2011
Wow, the generated C code actually contains "c2_r = c2_xi / 0.0;"! I am speechless! Without seeing your MATLAB function, I don't think there is much to help. You could post your M code here, or contact TWM tech support for help.
Walter Roberson
el 23 de Nov. de 2011
If I read the filename correctly, it seems more likely that it is the simulink portion that is generating the division by 0. But only more likely, not a certainty.
Fangjun Jiang
el 23 de Nov. de 2011
Yes. The C code is generated but the source my be in the M code, or could be the problem of the code generation.
Zachary Santer
el 25 de Nov. de 2011
Kaustubha Govind
el 23 de Nov. de 2011
0 votos
There seems to be have been a similar bug before. See Bug#534529. However, since it was fixed in R2009b, it is likely not the same issue.
You could however try the workaround suggested that Bug Report and see if it works for you:
- In the Simulink Editor, select Simulation > Configuration Parameters.
- In the Configuration Parameters dialog box, select Optimization.
- Change the Loop unrolling threshold value to 1, or to any number smaller than the length of the vector passed to norm.
If not, I would recommend reporting this to MathWorks Tech Support to see if this really is another bug.
1 comentario
Zachary Santer
el 23 de Nov. de 2011
Categorías
Más información sobre Naming Conventions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!