Use mldivide function with quantized values

1 visualización (últimos 30 días)
Andrea Alfonsi
Andrea Alfonsi el 3 de Abr. de 2022
Respondida: Avadhoot el 20 de Nov. de 2023
I'm trying to sove the problem where both A and b are quantized values created using
q = quantizer('Mode', 'fixed', 'Format', [h, k]);
with both h and k arbitrary integers.
When I try to compute A\b to find the solution, the result vector x is made of double values. Is there a way to force MATLAB use quantized values all over the execution of mldivide function istead of converting the result at the end?
I tryied with both \ and mldivide but the result were equivalent.

Respuestas (1)

Avadhoot
Avadhoot el 20 de Nov. de 2023
Hi Andrea,
I understand that you are trying to use the mldivide” operator on quantized values. The result you get is a vector of double values because “mldivide” is designed to work with only 3 data types. They are as follows:
  • Numeric
  • Char
  • Logical
In this case when you use the “quantize” function to quantize the matrices A and b, the output you get is still a matrix of doubles, just the values have been quantized. MATLAB doesn’t create a special datatype for the quantized values.
If you want to create a special data type for the quantized variables, you can use the "fi" function from the Fixed Point Designer toolbox. Here's an example:
A_fixed = fi(A, true,h, k);
b_fixed = fi(b, true,h, k);
This will create variables named as “A_fixed” and “b_fixed” which will be of type “embedded.fi”, which is a fixed-point data type. The “mldivide” function cannot work with this data type and will throw an error like below:
Error using \
Arguments must be numeric, char, or logical.
The “mldivide” function is optimized to work with double precision floating point values, hence the result you get is a vector of doubles. Even if you use quantized values in all the preceding steps of your calculation, the “mldivide” operation will operate only with numeric values You would have to quantize the result after the “mldivide” operation to get your desired quantized result.
Refer to the below documentation links for more information:
  1. mldivide” function: https://www.mathworks.com/help/matlab/ref/mldivide.html?s_tid=doc_ta#btg5qam-2
  2. The “fi” function: https://www.mathworks.com/help/fixedpoint/ref/embedded.fi.html
  3. The “quantize” function: https://www.mathworks.com/help/fixedpoint/ref/embedded.fi.quantize.html
I hope this helps.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by