Is it possible that the "m. file" code is converted from the double precision to the single precision??

1 ビュー (過去 30 日間)
Changwoo Lee
Changwoo Lee 2021 年 11 月 29 日
編集済み: Andy Bartlett 2021 年 12 月 6 日
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.
  6 件のコメント
dpb
dpb 2021 年 11 月 29 日
I don't have the coder so can't test/experiment, but looks to me by the error messages it spit out like there are further input parameters to the conversion routine you could specify to let it know the data types of the input arguments and other refinements that could be tried before completely giving up on the conversion process.

サインインしてコメントする。

採用された回答

Jan
Jan 2021 年 11 月 29 日
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.
  2 件のコメント
Changwoo Lee
Changwoo Lee 2021 年 11 月 29 日
I was wondering if there is a better way, but there doesn't seem to be an easy way...
Thank you very much.

サインインしてコメントする。

その他の回答 (1 件)

Andy Bartlett
Andy Bartlett 2021 年 12 月 6 日
編集済み: Andy Bartlett 2021 年 12 月 6 日
Hi,
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.
Andy

カテゴリ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by