- Split the computation into smaller pieces: If the integer values used in your MATLAB function are part of a large computation, you can split the computation into smaller pieces to avoid integer overflow errors.
- Use modular arithmetic if possible: If the integer values used in your function are only used in arithmetic operations such as addition, subtraction, multiplication, or division, you can use modular arithmetic to avoid integer overflow errors.
Simplify handle function values for export to c++
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I have some handle functions that I need to export to c++, but my issue is that this functions have inside very large integer values so i'm struggling then in c++ as I cant store those large int numbers.
So to solve that, I'm trying to somehow simplify this functions before exporting. I did a trial but the resulting values are the same than the input ones so, its not simplifying. I dont know if my approach is good, but I dont have more Ideas on how to overcome this problem.
I attached my functions "fregs_TX90.mat" and a little script with my trial on one of those functions:
clear all;
close all;
clc;
%%
load('fregs_TX90.mat', "q","dq","ddq","freg","fregM","fregG","fregCentr","fregCentrCor","fregCentrCorG","fregFric","fregCentr","fregCor");
%%
clc;
%fregMat=freg(ddq(1),ddq(2),ddq(3),ddq(4),ddq(5),ddq(6),dq(1),dq(2),dq(3),dq(4),dq(5),dq(6), q(2),q(3),q(4),q(5),q(6));
fregMMat= fregM(q(2),q(3),q(4),q(5),q(6));
% fregGMat= fregG(q(2),q(3),q(4),q(5),q(6));
%fregCentrCorMat= fregCentrCor(dq(1),dq(2),dq(3),dq(4),dq(5),dq(6), q(2),q(3),q(4),q(5),q(6));
%fregCentrCorGMat= fregCentrCorG(dq(1),dq(2),dq(3),dq(4),dq(5),dq(6), q(2),q(3),q(4),q(5),q(6));
% fregFricMat= fregFric(dq(1),dq(2),dq(3),dq(4),dq(5),dq(6));
% fregCorMat= fregCor(q(2),q(3),q(4),q(5),q(6));
%fregCentrMat= fregCentr(q(2),q(3),q(4),q(5),q(6));
fregMMatsimp=simplify(fregMMat)
0 个评论
回答(1 个)
Amit Dhakite
2023-4-12
编辑:Amit Dhakite
2023-4-12
Hi Mikel,
As per my understanding, you want to convert your MATLAB code to C++ code, but the large integer values are not supported in C++.
It's not clear what exactly the fregM() function is doing, but I can suggest some general measures you may consider to avoid these type of situations while implementing functions in MATLAB:
The simplify() function itself does not directly deal with overflows of integer values. It only simplifies expressions symbolically, without evaluating them numerically. However, it is possible that some expressions may result in an overflow even after using simplify() function.
With regards,
Amit
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!