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

카테고리

도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by