Hello,
I have been using the 'sco_sym2funcs' function to generate CoCo-compatible symbolic function encodings for my project and have run into the following error message when attempting to generate the function 'F_VAR.m' in line 67 of the attached code 'coupled/main.m':
Error: File: F_VAR.m Line: 1642 Column: 1
The function "ft_1" was closed with an 'end', but at least one other function definition was not. To avoid
confusion when using nested functions, it is illegal to use both conventions in the same file.
Error in sco_gen (line 46)
maxorder=fun('maxorder');
Error in sco_sym2funcs (line 151)
outstruc.fout=sco_gen(str2func(funcname));
Error in VAR_symbolic (line 76)
F_coco = sco_sym2funcs(F_seg, {u_vec, p_vec}, {'x', 'p'}, 'filename', filename_out);
Error in main (line 67)
funcs.VAR = VAR_symbolic(xdim, pdim, @coupled_Winfree_symbolic_field);
I have used sco_sym2funcs on several other symbolic vector fields other than the 'coupled/functions/fields/coupled_Winfree_symbolic_field.m' used in the attached code without encountering any errors. For example, I have also attached a function 'single/functions/fields/Winfree_symbolic_field.m' from which the function 'F_VAR.m' is generated without any issues in line 67 of the attached code 'single/main.m'.
It therefore seems to be an issue originating from the symbolic function generated by the 'coupled_Winfree_symbolic_field.m' function.
The error message does not occur consistently; I have managed to run the script 'coupled/main.m' and successfully generate 'F_VAR' once, and a colleague has also been able to do so without encountering any errors.
I am using the latest release of COCO (January 28, 2025) and MATLAB R2022b.
Any advice would be greatly appreciated. If there is any other information you need, please just let me know.
Thanks,
Alex
Dear Alex,
I forwarded your query to Jan Sieber (University of Exeter) who is the developer of symcoco. He shared the following (edited for clarity):
The outcome appears to depend on the version of Matlab used and does not occur with the version used by Jan.
The problem that you have encountered is mentioned in doc-src/symcoco-doc.pdf in the section that discusses inputs to sco_sym2funcs.
The symbolic code generation in the version used by you creates functions that sometimes include "end" and sometimes don't, depending on the complexity of the function created by the code and the creation of a subfunction to handle this complexity.
The only safe way (that should be version independent) is to call sco_symfuncs with the options 'multifile', true, and optionally (eg) 'folder','private' to put each created function into its own file, if desired into in a subfolder. The demo bistable in the symcoco contributed folder shows how this is done.
Please give this a try first and let us know if the problem persists, in which case we may recommend switching Matlab version, if possible.
Kind regards,
Harry
Thank you (and Jan) very much for your help, and for your quick response!
Your suggested solution works well. I have amended the functions to call sco_sym2funcs with the option 'multifile' set to 'true', and no longer encounter any errors in the symbolic code generation.
However, if I try to use the function
with ode45, for example,
I now encounter the following error message:
I have attached the updated code, with the example call to ode45 in line 92 of the script 'main.m'.
Thanks again for your help.
Alex
Dear Alex,
The debugging.zip was really helpful. When unpacking and running main, I got other errors:
so, I had to add many paths:
After adding these paths the
ode45call worked. I suspect that your error message comes because the ode45 uses aF_coupled_Winfree>F_coupled_Winfree_rhs_0that is still hanging around from previous code generation attempts in a folder that is in the path. As the files you generate do not have conflicting names, you could use the optionfor all your generated functions. Then all the generated files would be in this one folder, and you would not need to add so many paths. Could you try checking your paths?
Good catch - that was indeed the problem thank you. All working perfectly now. Thanks for your help!