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?

 Akzeptierte Antwort

Star Strider
Star Strider am 28 Jan. 2018

1 Stimme

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.

Weitere Antworten (0)

Produkte

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by