reduce the working precision
4 次查看(过去 30 天)
显示 更早的评论
I have some 2 dimesional array (varaibles), like A(100, 100), B(100, 100). Matlab takes 16 decimal places for all calculations. But, I need to fix ONLY 6 decimal palces for all my calculations (numerical simulations). How do i fix all my varibales in my code with only 6 or 8 decimal places.
0 个评论
回答(2 个)
Andy Bartlett
2021-6-7
I'm guessing you want your simulation code to be smaller and faster.
Single precision floating-point provides around 7 decimal digits of accuracy and can achieve that goal.
Make sure the key entry points to your algorithm are single.
If the inputs are all singles, most of your calculations will be produce single precision results.
A = single( rand(3,2) );
B = single( rand(2,4) );
C = A * B
C =
3×4 single matrix
0.68457 0.23552 0.11531 1.2855
0.39312 0.13022 0.069436 0.83144
0.59251 0.20564 0.098654 1.0794
Converting a MATLAB m-file from double precision to single precision can be automated using convertToSingle.
If you have a Simulink subsystem in double precision that you wanted to convert to single, the conversion can also be automated.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fixed-Point Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!