Reputation: 1668
I spent over an hour chasing a bug in my code which was leading to a precision error. It turned out that in one of my equations, I had forgotten to divide two vectors element-wise; I had written /
instead of ./
. Usually Matlab gives an error in these cases, e.g. if you try to multiply two vectors with *
instead of .*
. But in this case it's happily returning a scalar value! Is this supposed to happen, and does this value have any meaning?
For example,
x = 0 : 0.01 : 1;
y = x/exp(x);
sets y=0.3132
.
Upvotes: 2
Views: 135
Reputation: 125874
Yes, this is supposed to happen. You used the matrix right division operator /
, and in this particular case it found a scalar value of y
that solved the following system of equations in a least-squares sense:
y*exp(x) = x;
Upvotes: 2