There is one thing I do not like on Matlab: It tries sometimes to be too smart. For instance, if I have a negative square root like
a = -1; sqrt(a)
Matlab does not throw an error but switches silently to complex numbers. The same happens for negative logarithms. This can lead to hard to find errors in a more complicated algorithm.
A similar problem is that Matlab "solves" silently non quadratic linear systems like in the following example:
A=eye(3,2); b=ones(3,1); x = A \ b
Obviously x
does not satisfy A*x==b
(It solves a least square problem instead).
Is there any possibility to turn that "features" off, or at least let Matlab print a warning message in this cases? That would really helps a lot in many situations.
f=@(x) x*((x+1)/x)
gives the resultf([1,2])=[1.6,3.2]
whereas most beginners would expect the result[2,3]
. In a larger program such bugs are very hard to find. – Mulchdbstop if complex
using conditional breakpoints with the condition~isreal
. Not exactly the same, but close. – Trish