3

I am using Matlab and using numbers in scientific notation, which are represented with the letter e for the exponent. An example in Matlab:

>> 2e5
ans =
200000

Now would like to work with numbers in scientific notation, but using variables to hold the values of the mantissa and the exponent (left and right side of the e respectively). I do not understand how this can be done without the variable names merging with the letter e for the exponent. Eg:

>> rr=5;
>> 2err
??? 2err
|
Error: Unexpected MATLAB operator.

Can this still be done? Or must I use the manual approach:

>> 2*10^rr
ans =
200000
Vass
  • 2,682
  • 13
  • 41
  • 60
  • 1
    `2*10^rr` is the answer. There is no `e` operator like you are looking for. – Pursuit Mar 11 '12 at 14:39
  • 3
    I'm curious as to why you're doing this in the first place. If it's so you can maintain precision over a larger range of numbers, there's decimal data types or extended-precision/arbitrary-precision math for that. Don't reinvent the wheel! – Li-aung Yip Mar 11 '12 at 15:18

1 Answers1

3

You must use the manual approach; you can't use scientific notation like that with variables. You might want to use 2.*10.^rr, with the ., to enable you to use the same statement with arrays of numbers.

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64