Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large numbers multiplication in MATLAB

Tags:

matlab

I have a question out of sheer curiosity. How is multiplication of large numbers implemented in MATLAB ? Is it Karatsuba,Toom-3, Fürer or something entirely different ?

like image 288
slezadav Avatar asked Sep 21 '12 08:09

slezadav


People also ask

How do you multiply numbers in MATLAB?

C = A . * B multiplies arrays A and B by multiplying corresponding elements. The sizes of A and B must be the same or be compatible. If the sizes of A and B are compatible, then the two arrays implicitly expand to match each other.

What is the difference between * and * in MATLAB?

* is matrix multiplication while . * is elementwise multiplication. In order to use the first operator, the operands should obey matrix multiplication rules in terms of size. Show activity on this post.

How do you find large numbers in MATLAB?

More Answers (1)Use Symbolic Math Toolbox. Be careful not to perform computations in double that result in values greater than flintmax and then convert the results to sym. Convert exact quantities to sym and perform the calculations symbolically.

Why do we use * in MATLAB?

MATLAB matches all characters in the name exactly except for the wildcard character * , which can match any one or more characters.


1 Answers

If you are interested in the algorithm for computing for example 139676498390139139676498390676498390*8745566554641239676498390676498390, then this is what happens:

  • both numbers are converted to double in IEEE® Standard 754
  • as such, the representation is not accurate, because doubles can only accurately represent integers of up to 2^53-1 (check documentation of bitmax function) (~10^15, while your numbers are on the order of 10^35).
  • multiplication is performed using double precision floating point numbers, and is thus also approximate

Have a look at this example code:

>> a=139676498390139139676498390676498390;
>> num2str(a)

ans =

139676498390139141600015724509659136

which is clearly not exactly the value you assigned to a - only the first 16 digits match.

like image 149
angainor Avatar answered Sep 19 '22 15:09

angainor