1

I don't understand what some behavior in Matlab 2013a, with the functions dot and cross.

I have 2 vectors as a basis of a plane: v1 = [-0.3134 , 0.0079 , 0.0072] v2 = [-0.1132 , 1.1473 , 0.1586]

If I compute C = v1xv2 (cross product), then I will have the normal vector of the plane formed by v1 and v2: C= cross(v1,v2) C = [-0.0070 , 0.0489 , -0.3587]

But when i probe that this vectors must to be orthogonally, C and v1 are not.

dot(C,v1) = 4.3368e-19 dot(C,v2) = 0

I verify manually the dot product of C dot v1, effectively, is not zero

What is the problem , my version of matlab ? or my computer architecture (Intel I7)?

Carl
  • 113
  • 1
  • 14
  • 3
    well 4.3368e-19 is pretty close to 0 isn't it? It's due to floating-point arithmetic: http://matlabgeeks.com/tips-tutorials/floating-point-numbers-in-matlab-2/ – Benoit_11 Oct 07 '14 at 17:23
  • 3
    this question comes up every single day... read here: [click me](http://stackoverflow.com/questions/686439/why-is-24-0000-not-equal-to-24-0000-in-matlab). – Robert Seifert Oct 07 '14 at 17:36
  • 1
    Always bear in mind that MatLab aims for computational efficiency in numerical calculations, rather than precision. Still it's pretty much precise, 4e-19 is close enough to 0 in virtually any application. If not, you need to scale, rather than seek this kind of precision – Inox Oct 07 '14 at 18:03
  • 1
    @thewaywewalk - This as well as `imshow` mixing `double` and `uint8` problems are the two most frequent things people with MATLAB questions ask often when I visit StackOverflow. – rayryeng Oct 07 '14 at 18:20
  • Sorry guys, for me zero is very different of 4e-19, for example if you take the log10(4e-19) is approx. -18. for many engineering calculations that can lead to a collapse. Thanks by the comments and suggestions. – Carl Oct 08 '14 at 19:10

1 Answers1

3

Both the cross product C and its dot product with v1 and v2 will be contaminated by small amounts of round-off error. You can estimate the magnitude of such errors with the MATLAB eps feature (see http://www.mathworks.com/help/matlab/ref/eps.html), which returns your machine's floating-point precision. The most meaningful way to test whether a floating point number is "zero" is to compare it to eps, via something like:

dot(C,v1)<eps
Sesquipedal
  • 228
  • 2
  • 11