Can someone briefly explain fixed-point? MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter mikeph
  • Start date Start date
  • Tags Tags
    Explain Matlab
Click For Summary

Discussion Overview

The discussion revolves around the use of the fixed-point function fi() in MATLAB, particularly regarding issues of precision and representation of large numbers. Participants explore the limitations of fixed-point representation and consider alternatives for achieving accurate multiplication of large integers.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant expresses confusion over why using fi(3336770033) results in a different number (3336830976), questioning the toolbox's capability for accurate representation without moving decimals.
  • Another participant suggests that the issue may stem from MATLAB's default word size for the fi function being 16 bits, which could limit significant digits.
  • A third participant notes that to retain full significance when multiplying large numbers, the Symbolic Toolbox may be necessary, referencing its use of MuPad.
  • Some participants clarify that the fi() function defaults to 16-bit word length, which may not suffice for the desired precision, implying that more significant digits would require a different approach.
  • One participant points out that the representation of numbers in MATLAB can show accurate digits if not constrained by the fixed-point representation.
  • A later reply suggests examining the hexadecimal representation of the numbers to understand the loss of precision, indicating that the discrepancy may be due to trailing zeros being lost in the conversion.

Areas of Agreement / Disagreement

Participants generally agree that the fixed-point representation has limitations, particularly regarding significant digits. However, there is no consensus on the best approach to achieve the desired precision, with differing views on the use of the Symbolic Toolbox versus fixed-point representation.

Contextual Notes

Limitations include the default word size of the fi function and its implications for significant digits. The discussion also highlights the potential need for additional toolboxes to achieve higher precision in calculations.

mikeph
Messages
1,229
Reaction score
18
Hi, I've been through the help files and demos but one question which I can't find the answer to is destroying my confidence with this toolbox.

If I write: a = fi(3336770033), why does it write 3336830976? I can't figure out why it's losing my number. I don't need any moving decimals, all I want to do is multiply this number a few times, and get the result with complete accuracy. 64 bits is not enough so floating point won't do.

Am I using the wrong toolbox for this purpose?

Thanks
 
Physics news on Phys.org
Hi MikeyW! :smile:

What you have is 32 bits floating point precision (about 6 significant digits).
Since the default of MATLAB is 64 bits precision, someone must have forced it down somewhere.

How is fi() defined?
Does it perhaps have a "single" precision floating point argument instead of a "double" precision argument?
 
According to the documentation, the default word size for the fixed point function fi is 16 bits.

If you want to multiply large numbers and retain full significance then you need the Symbolic Toolbox. I believe Matlab uses MuPad as the engine for its Symbolic Toolbox, which is the same as Mathcad ... I've attached a screenshot from Mathcad - is this what you want to do?
 

Attachments

  • phys - 12 06 09 symbolic multiplication 01.jpg
    phys - 12 06 09 symbolic multiplication 01.jpg
    9 KB · Views: 481
Sorry, I was not familiar with the fi() function yet.

From its description:
"fi(v) returns a signed fixed-point object with value v, 16-bit word length, and best-precision fraction length."

It seems to me that 16-bit word length implies at most 5 significant digits.
If you want more significant digits, you should not use this fi() function.

As you can see in your own screenshot, if you don't tell Matlab what to do with the representation of the numbers, it does just fine, showing as many accurate digits as you want.
 
I like Serena said:
Sorry, I was not familiar with the fi() function yet.

From its description:
"fi(v) returns a signed fixed-point object with value v, 16-bit word length, and best-precision fraction length."

It seems to me that 16-bit word length implies at most 5 significant digits.
If you want more significant digits, you should not use this fi() function.

As you can see in your own screenshot, if you don't tell Matlab what to do with the representation of the numbers, it does just fine, showing as many accurate digits as you want.
I'm not sure which message you are replying to here, but just in case its mine (because of mention of the screenshot) I just want to make clear that the screenshot is of Mathcad not Matlab. Mathcad has a version of the MuPad symbolic built into it, whereas the MuPad Symbolic Toolbox is an add-on for Matlab. Matlab normally operates at IEEE double floating-point precision giving something like 52 bits for the mantissa? ... or near enough for Government work, I think ... the relevant point being that standard Matlab will hit a precision limit pretty quickly when multiplying large (number of digits) numbers together.
 
Hmm, ok, thanks. I'm still not sure why fi(x) doesn't just give x, it's not like it can be limited by the bit size since the (incorrect) 3336830976 is the same length as my input 3336770033.

I'll give the symbolic toolbox a go, thanks.
 
MikeyW said:
Hmm, ok, thanks. I'm still not sure why fi(x) doesn't just give x, it's not like it can be limited by the bit size since the (incorrect) 3336830976 is the same length as my input 3336770033.

I'll give the symbolic toolbox a go, thanks.

Look at the two numbers in hex rather than decimal ... you should find that the 'incorrect' number has a string of zeros at the end, implying they've been lost as expected.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
8K
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
8K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
5
Views
8K
  • · Replies 10 ·
Replies
10
Views
18K
Replies
4
Views
2K