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?

 採用された回答

Star Strider
Star Strider 2018 年 1 月 28 日

1 投票

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.

その他の回答 (0 件)

カテゴリ

製品

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by