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?

 Accepted Answer

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.

More Answers (0)

Products

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!