From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: adding scalar to a vector in matlab
Date: Fri, 3 Feb 2012 04:03:11 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 21
Message-ID: <jgfm9v$fav$>
References: <jgfhi9$2dd$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1328241791 15711 (3 Feb 2012 04:03:11 GMT)
NNTP-Posting-Date: Fri, 3 Feb 2012 04:03:11 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:756587

"Srikrishna Mahadevan" <> wrote in message <jgfhi9$2dd$>...
> I am trying to offset my vector by a real number; but for some reason matlab makes it a decimal number when the offset is ~1000; Does anyone know why is this happening and how I can overcome it?
> Actually the added number is being converted to a decimal number.
- - - - - - - - - -
  It is not entirely clear what you mean by "converted to a decimal number".  However I am guessing you refer to the display of numbers using the default "format short" which Mathworks describes as "Scaled fixed-point format, with 4 digits after the decimalpoint. For example, 3.1416."  There are many other kinds of format used to display your numbers.  Look up the documentation on the 'format' instruction.

  However it is important for you to realize that these are simply different methods the matlab system uses to inform you about an internally-stored quantity.  With different formats the same number pi can appear as:

 3.2416  (short)
 3.14159265358979  (long)
 400921fb54442d18  (ieee hex)

Using for example "%16.10e" in fprintf you would see:


  All of these are attempts at showing you, the user, what quantity is contained within the computer, but that internal number is the same no matter how it is being displayed - computation results are unaffected by differences in display.  There is no "converting" taking place here.  In the standard type 'double' numbers the representation internally is actually in binary floating point using 64 bits.  The relationship to decimal numbers is only theoretical, achieved by way of format displays.  The above mysterious "ieee hex" format is the only one that corresponds exactly to the actual state of those 64 'double' bits.

  I would suggest you do some experimentation using many different formats on the same number to demonstrate all of this to your own satisfaction.

Roger Stafford