When I run this equation below I get a row vector (1 by 2 )
//
[ (9/4) + [(6/sqrt(2))*cos(pi/4)] +[2*cos(pi/4)*cos(pi/4)] ]
//
When I run equation directly below I get a scalar
//
[ 9/4 + (6/sqrt(2))*cos(pi/4) + 2*cos(pi/4)*cos(pi/4) ]
//
why causes this difference?

 Respuesta aceptada

Star Strider
Star Strider el 28 de En. de 2018

1 voto

It arises from the way MATLAB decides what constitute the elements of an array. The square brackets tell MATLAB that the contents of each are different elements of the vector. The lack of square brackets in the second one indicate that it is considered a single expression.
Note that if you make the operators in the second expression unitary operators rather than binary operators, you get a completely different result:
[ 9/4 +(6/sqrt(2))*cos(pi/4) +2*cos(pi/4)*cos(pi/4) ]
2.25 3 1
Be careful what you do with matrix elements, so that you get the result you want.

Más respuestas (0)

Categorías

Productos

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by