Why does MATLAB compute an equation involving a scalar and a matrix by algebraically working on the individual elements?
2 次查看(过去 30 天)
显示 更早的评论
I was working on curve fitting using Hermite polynomial where i had to compute a matrix equation (1-[vector]), where 'vector' represents a polynomial. The idea is to subtract the 1 with the 0 order term in the vector and get a new list of coefficients.The line of code was wrong and i changed the code to get the right result but i wonder why MATLAB didn't throw an error. E.g 1-[1 2]= 0 -1 according to MATLAB. Why does it go through?
0 个评论
采纳的回答
Walter Roberson
2016-11-27
It has been defined that way for a long long time. See for example the first example https://www.mathworks.com/help/matlab/ref/minus.html#examples
The operations + - .* .^ and ./ all automatically do expansion of scalars on one side to match the size of the other. The operation * with a scalar on one side is automatically treated as .* (that is, each element of the other side is multiplied by the scalar.) The operation / with a vector on the left side and a scalar on the right side is automatically treated as ./ (that is, each element of the left side is divided by the scalar.)
The one common situation that is not automatically expanded is / with scalar on the left and row vector on the right (which is an error.)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!