Is it possible that the "m. file" code is converted from the double precision to the single precision??
3 views (last 30 days)
I have "sqp.m" file which is attached here.
Is there anyway to convert this "m. file" from the double precision to the single precision??
(I found the below document and tried it, but it doesn't work.)
I wish that a result is "m.file" with 'single precision variables'
Thank you very much.
Jan on 29 Nov 2021
This function has been developped an tested since 1995. You cannot be sure, if it works correctly with singles as inputs.
converttosingle is an interesting idea. Unfortunately you explain only, that "it doesn't work" without mentioning the details.
With using the debugger, you should be able to find all commands, which create double arrays or rely on the inputs to be doubles. Most of all these are a lot of eps(), ones() and zeros() calls. In addition I find eye() and inf. Some constants as 0, 1 and 2 are occuring also, but they might be used as integers, e.g. in indices.
I would not rely on an automatic conversion, because for such a complicated code this is too fragile.
More Answers (1)
Andy Bartlett on 6 Dec 2021
Edited: Andy Bartlett on 6 Dec 2021
The tools for converting double precision floating-point to single precision for MATLAB code and Simulink models work best at converting designs that (aside from numeric efficiency needs like data types) are close to ready for a "specific" embedded usage.
General purpose MATLAB code based on default doubles and designed to handle a very wide set of situations, such as your SQP function, is much less likely to convert well as compared to a design that has been narrowed down to a specific embedded real-time need.
Since the example you provided, sqp, is doing Quadratic Programming, my answer to your other question might be helpful. That answer refers to the Model Predictive Controller that I believe uses Quadratic Programming on the inside and supports single precision sim and code generation.