필터 지우기
필터 지우기

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