Multiplying By 10000 vs 10^4

2 views (last 30 days)
Harel Harel Shattenstein on 27 Apr 2018
Edited: Stephan on 27 Apr 2018
Why
A=rand(3,3);
B=A(:)*10000;
is different from
A=rand(3,3);
B=A(:)*10^4;
Stephan on 27 Apr 2018
the way you wrote it, will generate a new matrix A with new random numbers, which will most likely not be the same as in the first run:
>> clear all
>> A = rand(3,3)
A =
0.9649 0.9572 0.1419
0.1576 0.4854 0.4218
0.9706 0.8003 0.9157
>> B= A(:)*10000
B =
1.0e+03 *
9.6489
1.5761
9.7059
9.5717
4.8538
8.0028
1.4189
4.2176
9.1574
>> A = rand(3,3)
A =
0.7922 0.0357 0.6787
0.9595 0.8491 0.7577
0.6557 0.9340 0.7431
>> C = A(:)*10^4
C =
1.0e+03 *
7.9221
9.5949
6.5574
0.3571
8.4913
9.3399
6.7874
7.5774
7.4313
>> Yes_it_is_the_same = B == C
Yes_it_is_the_same =
9×1 logical array
0
0
0
0
0
0
0
0
0
So you understand the difference between both versions?
bets regards

Stephan on 27 Apr 2018
See comments, when working with random numbers you have to understand, that everytime you use the command new random numbers will appear - thats the reason why you get different values for the supposed same thing.
Best regards
Stephan