Why does MATLAB compute an equation involving a scalar and a matrix by algebraically working on the individual elements?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Abhishek Pandey
el 27 de Nov. de 2016
Comentada: Abhishek Pandey
el 27 de Nov. de 2016
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 comentarios
Respuesta aceptada
Walter Roberson
el 27 de Nov. de 2016
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.)
Más respuestas (0)
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!