- Define a consistent fimath object: Create a fimath object with the desired properties and apply it to all fixed-point operations.
- Use the fimath object in your computation: Ensure that your calculations are using this fimath object.
What is the cause of the error message "FIMATH mismatch:Property 'ProductWordLength'" here?
2 views (last 30 days)
Show older comments
I get the error message
FIMATH mismatch:Property 'ProductWordLength': 16 ~= 32
from the following action code in a state transition table:
y = fi(10,0,32,10,'ProductMode','SpecifyPrecision','ProductWordLength',32,'ProductFractionLength',10)^x;
where x is defined as:
fixdt(0,8,5)
y is defined as:
fixdt(0,32,10)
The 16 seems to come frome the native number of bits in the hardware implementation details.
Following to this. Is there a short way to just calculate 10^x in the precision of y in StateFlow?
0 Comments
Answers (1)
Yash
on 23 Aug 2024
Hi Torsten,
The error you're encountering suggests a mismatch in the "ProductWordLength" property when performing the computations. The fi object you are creating for "y" specifies a ProductWordLength of 32, but somewhere in the computation, a ProductWordLength of 16 is being used, likely due to the default fimath settings or hardware constraints.
To calculate (10^x) with the precision of "y" in Stateflow, you can ensure the fimath properties are consistent across your calculations. Here's a way to do this:
Here's an example of how you can achieve this:
% Define the value of x (example value, replace with actual input)
x_value = 3; % Example: x = 3
% Create a fixed-point object for x with the specified type
x = fi(x_value, 0, 8, 5);
% Define a fimath object with consistent properties for the calculation
myFimath = fimath('ProductMode', 'SpecifyPrecision', ...
'ProductWordLength', 32, ...
'ProductFractionLength', 10, ...
'SumMode', 'SpecifyPrecision', ...
'SumWordLength', 32, ...
'SumFractionLength', 10);
% Set the fimath property of x
x.fimath = myFimath;
% Create a fixed-point object for the base number 10
base = fi(10, 0, 32, 10, 'fimath', myFimath);
% Calculate 10^x with the precision of y
y = base^x;
% Display the result
disp(['10^', num2str(x_value), ' = ', num2str(y)]);
Adjust the "x_value" to your specific needs or ensure that "x" is correctly defined elsewhere in your code. This approach should help resolve the fimath mismatch error and allow you to compute (10^x) using the desired precision.
0 Comments
See Also
Categories
Find more on Fixed Point in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!