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 CenterFile Exchange 中查找有关 Get 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