As part of a larger project, I have the following simple matrix multiplication:
c = a* b;
Where a is:
Columns 1 through 7 1.000000000000000 0.778800783071405 0.367879441171442 0.105399224561864 0.018315638888734 0.778800783071405 0.606530659712633 Columns 8 through 14 0.286504796860190 0.082084998623899 0.014264233908999 0.367879441171442 0.286504796860190 0.135335283236613 0.038774207831722 Column 15 0.006737946999085
and b is:
1.0e+02 * 1.681770403629075 -3.848571335694688 4.372852859312935 -3.552127988829399 4.433852194145209 -1.091783715227434 2.219644313019083 -1.858966831671062 0.917816691444462 -2.715630209256668 1.794744879202224 -4.126306698348984 4.755107353594159 -3.930478238870790 4.574731559033815
Giving the result for c:
-3.064215547965432e-14
However when I try to replicate this with the following test:
a = [1, 0.778800783071405, 0.367879441171442, 0.105399224561864, 0.018315638888734, 0.778800783071405, 0.606530659712633, 0.28650479686019, 0.082084998623899, 0.014264233908999, 0.367879441171442, 0.28650479686019, 0.135335283236612, 0.038774207831722, 0.006737946999085]; b = [168.1770403629075; -384.8571335694688; 437.2852859312935; -355.2127988829399; 443.3852194145209; -109.1783715227434; 221.9644313019083; -185.8966831671062; 91.7816691444462; -271.5630209256668; 179.4744879202224; -412.6306698348984; 475.5107353594159; -393.0478238870790; 457.4731559033815]; c = a* b;
My result for c is:
-5.813127756937320e-13
I assume this has something to do with floating point arithmetic and despite having the MatLab console set to format long I'm perhaps not seeing the full values of the data I'm then pasting in to my test code. If this is the case how does one work around it?
Thanks in advance
Best Answer