Problem about Inner product of matrix with two vectors

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












If A, B are two lists with length n and M is a n*n Matrices, then I want to compute the inner product of them B.M.A. The result should be a scalar however, what I get is a matrix. Any one knows what happened here? Thanks!
My code is below



A = Subscript[z, 0], Subscript[z, 1], Subscript[z, 2],
Subscript[z, 3], Subscript[z, 4];
B = Subscript[OverBar[z], 0], Subscript[OverBar[z], 1], Subscript[OverBar[z], 2],
Subscript[OverBar[z], 3], Subscript[OverBar[z], 4];

M = Chop[0.9947525414706575`,
0.014318078739690324` +
0.012070727204725996` I, -0.022576963511297447` +
0.017365770023498133` I,
0.028293920126770736` + 0.0041202947110136594` I,
0.02281394023398197` -
0.0005272617323759155` I, 0.014318078739690316` -
0.012070727204725998` I, 1.0089738927082252`,
0.02221807191535088` -
0.018113027609091715` I, -0.012682665041359427` -
0.010424540405231546` I, -0.055382503060447716` +
0.035624018712441564` I, -0.02257696351129744` -
0.017365770023498137` I,
0.022218071915350877` + 0.018113027609091715` I,
1.0204773571789212`, -0.0007522563609968502` +
0.026534550066808438` I,
0.0003575302509902032` -
0.0635032495006343` I, 0.028293920126770733` -
0.00412029471101366` I, -0.012682665041359427` +
0.010424540405231544` I, -0.000752256360996853` -
0.026534550066808438` I, 1.0132613424630528`,
0.059304690914936876` -
0.01648460212183861` I, 0.02281394023398197` +
0.0005272617323759158` I, -0.055382503060447716` -
0.035624018712441564` I,
0.0003575302509902011` + 0.06350324950063431` I,
0.059304690914936876` + 0.016484602121838613` I,
0.9911763824117488`]

In[31]:= Dimensions[B.M.A]

Out[31]= 5









share|improve this question



















  • 1




    You must keep in mind that everything is an expression. Your calculation results in a symbolic sum of five terms; see FullForm[A.M.B]. Dimensions is returning the dimensions of the head of the expression (Plus) which has 5 terms.
    – Edmund
    34 mins ago










  • @Edmund Thanks for your explanation! I understand now!
    – cwei
    19 mins ago














up vote
1
down vote

favorite












If A, B are two lists with length n and M is a n*n Matrices, then I want to compute the inner product of them B.M.A. The result should be a scalar however, what I get is a matrix. Any one knows what happened here? Thanks!
My code is below



A = Subscript[z, 0], Subscript[z, 1], Subscript[z, 2],
Subscript[z, 3], Subscript[z, 4];
B = Subscript[OverBar[z], 0], Subscript[OverBar[z], 1], Subscript[OverBar[z], 2],
Subscript[OverBar[z], 3], Subscript[OverBar[z], 4];

M = Chop[0.9947525414706575`,
0.014318078739690324` +
0.012070727204725996` I, -0.022576963511297447` +
0.017365770023498133` I,
0.028293920126770736` + 0.0041202947110136594` I,
0.02281394023398197` -
0.0005272617323759155` I, 0.014318078739690316` -
0.012070727204725998` I, 1.0089738927082252`,
0.02221807191535088` -
0.018113027609091715` I, -0.012682665041359427` -
0.010424540405231546` I, -0.055382503060447716` +
0.035624018712441564` I, -0.02257696351129744` -
0.017365770023498137` I,
0.022218071915350877` + 0.018113027609091715` I,
1.0204773571789212`, -0.0007522563609968502` +
0.026534550066808438` I,
0.0003575302509902032` -
0.0635032495006343` I, 0.028293920126770733` -
0.00412029471101366` I, -0.012682665041359427` +
0.010424540405231544` I, -0.000752256360996853` -
0.026534550066808438` I, 1.0132613424630528`,
0.059304690914936876` -
0.01648460212183861` I, 0.02281394023398197` +
0.0005272617323759158` I, -0.055382503060447716` -
0.035624018712441564` I,
0.0003575302509902011` + 0.06350324950063431` I,
0.059304690914936876` + 0.016484602121838613` I,
0.9911763824117488`]

In[31]:= Dimensions[B.M.A]

Out[31]= 5









share|improve this question



















  • 1




    You must keep in mind that everything is an expression. Your calculation results in a symbolic sum of five terms; see FullForm[A.M.B]. Dimensions is returning the dimensions of the head of the expression (Plus) which has 5 terms.
    – Edmund
    34 mins ago










  • @Edmund Thanks for your explanation! I understand now!
    – cwei
    19 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











If A, B are two lists with length n and M is a n*n Matrices, then I want to compute the inner product of them B.M.A. The result should be a scalar however, what I get is a matrix. Any one knows what happened here? Thanks!
My code is below



A = Subscript[z, 0], Subscript[z, 1], Subscript[z, 2],
Subscript[z, 3], Subscript[z, 4];
B = Subscript[OverBar[z], 0], Subscript[OverBar[z], 1], Subscript[OverBar[z], 2],
Subscript[OverBar[z], 3], Subscript[OverBar[z], 4];

M = Chop[0.9947525414706575`,
0.014318078739690324` +
0.012070727204725996` I, -0.022576963511297447` +
0.017365770023498133` I,
0.028293920126770736` + 0.0041202947110136594` I,
0.02281394023398197` -
0.0005272617323759155` I, 0.014318078739690316` -
0.012070727204725998` I, 1.0089738927082252`,
0.02221807191535088` -
0.018113027609091715` I, -0.012682665041359427` -
0.010424540405231546` I, -0.055382503060447716` +
0.035624018712441564` I, -0.02257696351129744` -
0.017365770023498137` I,
0.022218071915350877` + 0.018113027609091715` I,
1.0204773571789212`, -0.0007522563609968502` +
0.026534550066808438` I,
0.0003575302509902032` -
0.0635032495006343` I, 0.028293920126770733` -
0.00412029471101366` I, -0.012682665041359427` +
0.010424540405231544` I, -0.000752256360996853` -
0.026534550066808438` I, 1.0132613424630528`,
0.059304690914936876` -
0.01648460212183861` I, 0.02281394023398197` +
0.0005272617323759158` I, -0.055382503060447716` -
0.035624018712441564` I,
0.0003575302509902011` + 0.06350324950063431` I,
0.059304690914936876` + 0.016484602121838613` I,
0.9911763824117488`]

In[31]:= Dimensions[B.M.A]

Out[31]= 5









share|improve this question















If A, B are two lists with length n and M is a n*n Matrices, then I want to compute the inner product of them B.M.A. The result should be a scalar however, what I get is a matrix. Any one knows what happened here? Thanks!
My code is below



A = Subscript[z, 0], Subscript[z, 1], Subscript[z, 2],
Subscript[z, 3], Subscript[z, 4];
B = Subscript[OverBar[z], 0], Subscript[OverBar[z], 1], Subscript[OverBar[z], 2],
Subscript[OverBar[z], 3], Subscript[OverBar[z], 4];

M = Chop[0.9947525414706575`,
0.014318078739690324` +
0.012070727204725996` I, -0.022576963511297447` +
0.017365770023498133` I,
0.028293920126770736` + 0.0041202947110136594` I,
0.02281394023398197` -
0.0005272617323759155` I, 0.014318078739690316` -
0.012070727204725998` I, 1.0089738927082252`,
0.02221807191535088` -
0.018113027609091715` I, -0.012682665041359427` -
0.010424540405231546` I, -0.055382503060447716` +
0.035624018712441564` I, -0.02257696351129744` -
0.017365770023498137` I,
0.022218071915350877` + 0.018113027609091715` I,
1.0204773571789212`, -0.0007522563609968502` +
0.026534550066808438` I,
0.0003575302509902032` -
0.0635032495006343` I, 0.028293920126770733` -
0.00412029471101366` I, -0.012682665041359427` +
0.010424540405231544` I, -0.000752256360996853` -
0.026534550066808438` I, 1.0132613424630528`,
0.059304690914936876` -
0.01648460212183861` I, 0.02281394023398197` +
0.0005272617323759158` I, -0.055382503060447716` -
0.035624018712441564` I,
0.0003575302509902011` + 0.06350324950063431` I,
0.059304690914936876` + 0.016484602121838613` I,
0.9911763824117488`]

In[31]:= Dimensions[B.M.A]

Out[31]= 5






matrix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Carl Woll

62.4k281158




62.4k281158










asked 1 hour ago









cwei

654




654







  • 1




    You must keep in mind that everything is an expression. Your calculation results in a symbolic sum of five terms; see FullForm[A.M.B]. Dimensions is returning the dimensions of the head of the expression (Plus) which has 5 terms.
    – Edmund
    34 mins ago










  • @Edmund Thanks for your explanation! I understand now!
    – cwei
    19 mins ago












  • 1




    You must keep in mind that everything is an expression. Your calculation results in a symbolic sum of five terms; see FullForm[A.M.B]. Dimensions is returning the dimensions of the head of the expression (Plus) which has 5 terms.
    – Edmund
    34 mins ago










  • @Edmund Thanks for your explanation! I understand now!
    – cwei
    19 mins ago







1




1




You must keep in mind that everything is an expression. Your calculation results in a symbolic sum of five terms; see FullForm[A.M.B]. Dimensions is returning the dimensions of the head of the expression (Plus) which has 5 terms.
– Edmund
34 mins ago




You must keep in mind that everything is an expression. Your calculation results in a symbolic sum of five terms; see FullForm[A.M.B]. Dimensions is returning the dimensions of the head of the expression (Plus) which has 5 terms.
– Edmund
34 mins ago












@Edmund Thanks for your explanation! I understand now!
– cwei
19 mins ago




@Edmund Thanks for your explanation! I understand now!
– cwei
19 mins ago










2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










Dimensions works for arbitrary heads. If you restrict to only allowing a List head:



Dimensions[B.M.A, AllowedHeads->List]









share|improve this answer




















  • Thank you for your reply! However, what I really want is to make sure this result is a scalar. This is only an Intermediate result. I need to use it do more complicated linear algebra computation.
    – cwei
    58 mins ago







  • 1




    @cwei I fail to see why my code doesn't suffice. Perhaps you could use ListQ[B.M.A] instead.
    – Carl Woll
    56 mins ago










  • Or ArrayQ. Maybe also TensorQ?
    – Henrik Schumacher
    49 mins ago










  • @CarlWoll Problem solved! Your answer is correct! Thanks!
    – cwei
    40 mins ago










  • @HenrikSchumacher Yes! They work as well! Thanks!
    – cwei
    40 mins ago

















up vote
1
down vote













Here's a simple example:



a = RandomReal[-1, 1, 10];
b = RandomReal[-1, 1, 10];
m = RandomReal[-1, 1, 10, 10];
a.m.b


This does give a scalar answer, as expected.






share|improve this answer




















  • Thanks! Yes! It works for numbers. But for an expression involved with variables. Dimension[expr] does not work properly if you don't specify head explicitly.
    – cwei
    32 mins ago










  • I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
    – bill s
    30 mins ago










  • Yes! I understand your example.
    – cwei
    21 mins ago











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184653%2fproblem-about-inner-product-of-matrix-with-two-vectors%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










Dimensions works for arbitrary heads. If you restrict to only allowing a List head:



Dimensions[B.M.A, AllowedHeads->List]









share|improve this answer




















  • Thank you for your reply! However, what I really want is to make sure this result is a scalar. This is only an Intermediate result. I need to use it do more complicated linear algebra computation.
    – cwei
    58 mins ago







  • 1




    @cwei I fail to see why my code doesn't suffice. Perhaps you could use ListQ[B.M.A] instead.
    – Carl Woll
    56 mins ago










  • Or ArrayQ. Maybe also TensorQ?
    – Henrik Schumacher
    49 mins ago










  • @CarlWoll Problem solved! Your answer is correct! Thanks!
    – cwei
    40 mins ago










  • @HenrikSchumacher Yes! They work as well! Thanks!
    – cwei
    40 mins ago














up vote
4
down vote



accepted










Dimensions works for arbitrary heads. If you restrict to only allowing a List head:



Dimensions[B.M.A, AllowedHeads->List]









share|improve this answer




















  • Thank you for your reply! However, what I really want is to make sure this result is a scalar. This is only an Intermediate result. I need to use it do more complicated linear algebra computation.
    – cwei
    58 mins ago







  • 1




    @cwei I fail to see why my code doesn't suffice. Perhaps you could use ListQ[B.M.A] instead.
    – Carl Woll
    56 mins ago










  • Or ArrayQ. Maybe also TensorQ?
    – Henrik Schumacher
    49 mins ago










  • @CarlWoll Problem solved! Your answer is correct! Thanks!
    – cwei
    40 mins ago










  • @HenrikSchumacher Yes! They work as well! Thanks!
    – cwei
    40 mins ago












up vote
4
down vote



accepted







up vote
4
down vote



accepted






Dimensions works for arbitrary heads. If you restrict to only allowing a List head:



Dimensions[B.M.A, AllowedHeads->List]









share|improve this answer












Dimensions works for arbitrary heads. If you restrict to only allowing a List head:



Dimensions[B.M.A, AllowedHeads->List]










share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









Carl Woll

62.4k281158




62.4k281158











  • Thank you for your reply! However, what I really want is to make sure this result is a scalar. This is only an Intermediate result. I need to use it do more complicated linear algebra computation.
    – cwei
    58 mins ago







  • 1




    @cwei I fail to see why my code doesn't suffice. Perhaps you could use ListQ[B.M.A] instead.
    – Carl Woll
    56 mins ago










  • Or ArrayQ. Maybe also TensorQ?
    – Henrik Schumacher
    49 mins ago










  • @CarlWoll Problem solved! Your answer is correct! Thanks!
    – cwei
    40 mins ago










  • @HenrikSchumacher Yes! They work as well! Thanks!
    – cwei
    40 mins ago
















  • Thank you for your reply! However, what I really want is to make sure this result is a scalar. This is only an Intermediate result. I need to use it do more complicated linear algebra computation.
    – cwei
    58 mins ago







  • 1




    @cwei I fail to see why my code doesn't suffice. Perhaps you could use ListQ[B.M.A] instead.
    – Carl Woll
    56 mins ago










  • Or ArrayQ. Maybe also TensorQ?
    – Henrik Schumacher
    49 mins ago










  • @CarlWoll Problem solved! Your answer is correct! Thanks!
    – cwei
    40 mins ago










  • @HenrikSchumacher Yes! They work as well! Thanks!
    – cwei
    40 mins ago















Thank you for your reply! However, what I really want is to make sure this result is a scalar. This is only an Intermediate result. I need to use it do more complicated linear algebra computation.
– cwei
58 mins ago





Thank you for your reply! However, what I really want is to make sure this result is a scalar. This is only an Intermediate result. I need to use it do more complicated linear algebra computation.
– cwei
58 mins ago





1




1




@cwei I fail to see why my code doesn't suffice. Perhaps you could use ListQ[B.M.A] instead.
– Carl Woll
56 mins ago




@cwei I fail to see why my code doesn't suffice. Perhaps you could use ListQ[B.M.A] instead.
– Carl Woll
56 mins ago












Or ArrayQ. Maybe also TensorQ?
– Henrik Schumacher
49 mins ago




Or ArrayQ. Maybe also TensorQ?
– Henrik Schumacher
49 mins ago












@CarlWoll Problem solved! Your answer is correct! Thanks!
– cwei
40 mins ago




@CarlWoll Problem solved! Your answer is correct! Thanks!
– cwei
40 mins ago












@HenrikSchumacher Yes! They work as well! Thanks!
– cwei
40 mins ago




@HenrikSchumacher Yes! They work as well! Thanks!
– cwei
40 mins ago










up vote
1
down vote













Here's a simple example:



a = RandomReal[-1, 1, 10];
b = RandomReal[-1, 1, 10];
m = RandomReal[-1, 1, 10, 10];
a.m.b


This does give a scalar answer, as expected.






share|improve this answer




















  • Thanks! Yes! It works for numbers. But for an expression involved with variables. Dimension[expr] does not work properly if you don't specify head explicitly.
    – cwei
    32 mins ago










  • I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
    – bill s
    30 mins ago










  • Yes! I understand your example.
    – cwei
    21 mins ago















up vote
1
down vote













Here's a simple example:



a = RandomReal[-1, 1, 10];
b = RandomReal[-1, 1, 10];
m = RandomReal[-1, 1, 10, 10];
a.m.b


This does give a scalar answer, as expected.






share|improve this answer




















  • Thanks! Yes! It works for numbers. But for an expression involved with variables. Dimension[expr] does not work properly if you don't specify head explicitly.
    – cwei
    32 mins ago










  • I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
    – bill s
    30 mins ago










  • Yes! I understand your example.
    – cwei
    21 mins ago













up vote
1
down vote










up vote
1
down vote









Here's a simple example:



a = RandomReal[-1, 1, 10];
b = RandomReal[-1, 1, 10];
m = RandomReal[-1, 1, 10, 10];
a.m.b


This does give a scalar answer, as expected.






share|improve this answer












Here's a simple example:



a = RandomReal[-1, 1, 10];
b = RandomReal[-1, 1, 10];
m = RandomReal[-1, 1, 10, 10];
a.m.b


This does give a scalar answer, as expected.







share|improve this answer












share|improve this answer



share|improve this answer










answered 41 mins ago









bill s

51.8k375146




51.8k375146











  • Thanks! Yes! It works for numbers. But for an expression involved with variables. Dimension[expr] does not work properly if you don't specify head explicitly.
    – cwei
    32 mins ago










  • I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
    – bill s
    30 mins ago










  • Yes! I understand your example.
    – cwei
    21 mins ago

















  • Thanks! Yes! It works for numbers. But for an expression involved with variables. Dimension[expr] does not work properly if you don't specify head explicitly.
    – cwei
    32 mins ago










  • I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
    – bill s
    30 mins ago










  • Yes! I understand your example.
    – cwei
    21 mins ago
















Thanks! Yes! It works for numbers. But for an expression involved with variables. Dimension[expr] does not work properly if you don't specify head explicitly.
– cwei
32 mins ago




Thanks! Yes! It works for numbers. But for an expression involved with variables. Dimension[expr] does not work properly if you don't specify head explicitly.
– cwei
32 mins ago












I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
– bill s
30 mins ago




I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
– bill s
30 mins ago












Yes! I understand your example.
– cwei
21 mins ago





Yes! I understand your example.
– cwei
21 mins ago


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184653%2fproblem-about-inner-product-of-matrix-with-two-vectors%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery