Borrar filtros
Borrar filtros

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)
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?

Respuesta aceptada

Walter Roberson
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.)
  1 comentario
Abhishek Pandey
Abhishek Pandey el 27 de Nov. de 2016
Yes, i actually went to the documentation mentioned by you after i found the problem in my code and checked it. Probably, it was wrong on my part to expect that the operation would follow all the matrix properties. Thank you very much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Polynomials en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by