Effacer les filtres
Effacer les filtres

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

5 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Matt J
Matt J le 5 Jan 2020
Modifié(e) : Matt J le 5 Jan 2020
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

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by