フィルターのクリア

Vector multiplication for a vector with a transpose of vector i.e. one row vector and one column vector.

5 ビュー (過去 30 日間)
I am using this script to multiply two vectors as below:
%Parameters Declaration
S0T=[1,2,3,-1,-2]
S1T=[1,1,-2,2,-3]
S0=transpose(S0T)
S1=transpose(S1T)
S1=S0T*S0
S2=S0T*S1
S3=S1T*S0
S4=S1T*S1
But unfortunately I am not able to match the output with theoretical results as below:
Output:
S0T =
1 2 3 -1 -2
S1T =
1 1 -2 2 -3
S0 =
1
2
3
-1
-2
S1 =
1
1
-2
2
-3
S1 =
19
S2 =
19 38 57 -19 -38
S3 =
1
S4 =
19 19 -38 38 -57
>>
Theoretical Results:
S1=19 (This is correct)
S2=1 (This is Wrong as per Matlab results)
S3=1 (This is correct)
S4=19 (This is Wrong as per Matlab results)
Question: I want to know if there is a better commend/operator in MATLAB that can be used to multiply two vectors i.e. one row vector and one column vector.

採用された回答

Matt J
Matt J 2020 年 1 月 5 日
編集済み: Matt J 2020 年 1 月 5 日
It's because you redefined S1 in line 6. Use distinct variable names for your outputs:
S0T=[1,2,3,-1,-2]
S1T=[1,1,-2,2,-3]
S0=transpose(S0T)
S1=transpose(S1T)
A=S0T*S0
B=S0T*S1
C=S1T*S0
D=S1T*S1
A =
19
B =
1
C =
1
D =
19

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by