Problem about Inner product of matrix with two vectors
Clash 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
matrix
add a comment |Â
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
matrix
1
You must keep in mind that everything is an expression. Your calculation results in a symbolic sum of five terms; seeFullForm[A.M.B]
.Dimensions
is returning the dimensions of the head of the expression (Plus
) which has5
terms.
â Edmund
29 mins ago
@Edmund Thanks for your explanation! I understand now!
â cwei
14 mins ago
add a comment |Â
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
matrix
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
matrix
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; seeFullForm[A.M.B]
.Dimensions
is returning the dimensions of the head of the expression (Plus
) which has5
terms.
â Edmund
29 mins ago
@Edmund Thanks for your explanation! I understand now!
â cwei
14 mins ago
add a comment |Â
1
You must keep in mind that everything is an expression. Your calculation results in a symbolic sum of five terms; seeFullForm[A.M.B]
.Dimensions
is returning the dimensions of the head of the expression (Plus
) which has5
terms.
â Edmund
29 mins ago
@Edmund Thanks for your explanation! I understand now!
â cwei
14 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
29 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
29 mins ago
@Edmund Thanks for your explanation! I understand now!
â cwei
14 mins ago
@Edmund Thanks for your explanation! I understand now!
â cwei
14 mins ago
add a comment |Â
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]
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
53 mins ago
1
@cwei I fail to see why my code doesn't suffice. Perhaps you could useListQ[B.M.A]
instead.
â Carl Woll
50 mins ago
OrArrayQ
. Maybe alsoTensorQ
?
â Henrik Schumacher
43 mins ago
@CarlWoll Problem solved! Your answer is correct! Thanks!
â cwei
35 mins ago
@HenrikSchumacher Yes! They work as well! Thanks!
â cwei
34 mins ago
add a comment |Â
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.
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
26 mins ago
I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
â bill s
25 mins ago
Yes! I understand your example.
â cwei
15 mins ago
add a comment |Â
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]
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
53 mins ago
1
@cwei I fail to see why my code doesn't suffice. Perhaps you could useListQ[B.M.A]
instead.
â Carl Woll
50 mins ago
OrArrayQ
. Maybe alsoTensorQ
?
â Henrik Schumacher
43 mins ago
@CarlWoll Problem solved! Your answer is correct! Thanks!
â cwei
35 mins ago
@HenrikSchumacher Yes! They work as well! Thanks!
â cwei
34 mins ago
add a comment |Â
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]
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
53 mins ago
1
@cwei I fail to see why my code doesn't suffice. Perhaps you could useListQ[B.M.A]
instead.
â Carl Woll
50 mins ago
OrArrayQ
. Maybe alsoTensorQ
?
â Henrik Schumacher
43 mins ago
@CarlWoll Problem solved! Your answer is correct! Thanks!
â cwei
35 mins ago
@HenrikSchumacher Yes! They work as well! Thanks!
â cwei
34 mins ago
add a comment |Â
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]
Dimensions works for arbitrary heads. If you restrict to only allowing a List
head:
Dimensions[B.M.A, AllowedHeads->List]
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
53 mins ago
1
@cwei I fail to see why my code doesn't suffice. Perhaps you could useListQ[B.M.A]
instead.
â Carl Woll
50 mins ago
OrArrayQ
. Maybe alsoTensorQ
?
â Henrik Schumacher
43 mins ago
@CarlWoll Problem solved! Your answer is correct! Thanks!
â cwei
35 mins ago
@HenrikSchumacher Yes! They work as well! Thanks!
â cwei
34 mins ago
add a comment |Â
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
53 mins ago
1
@cwei I fail to see why my code doesn't suffice. Perhaps you could useListQ[B.M.A]
instead.
â Carl Woll
50 mins ago
OrArrayQ
. Maybe alsoTensorQ
?
â Henrik Schumacher
43 mins ago
@CarlWoll Problem solved! Your answer is correct! Thanks!
â cwei
35 mins ago
@HenrikSchumacher Yes! They work as well! Thanks!
â cwei
34 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
53 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
53 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
50 mins ago
@cwei I fail to see why my code doesn't suffice. Perhaps you could use
ListQ[B.M.A]
instead.â Carl Woll
50 mins ago
Or
ArrayQ
. Maybe also TensorQ
?â Henrik Schumacher
43 mins ago
Or
ArrayQ
. Maybe also TensorQ
?â Henrik Schumacher
43 mins ago
@CarlWoll Problem solved! Your answer is correct! Thanks!
â cwei
35 mins ago
@CarlWoll Problem solved! Your answer is correct! Thanks!
â cwei
35 mins ago
@HenrikSchumacher Yes! They work as well! Thanks!
â cwei
34 mins ago
@HenrikSchumacher Yes! They work as well! Thanks!
â cwei
34 mins ago
add a comment |Â
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.
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
26 mins ago
I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
â bill s
25 mins ago
Yes! I understand your example.
â cwei
15 mins ago
add a comment |Â
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.
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
26 mins ago
I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
â bill s
25 mins ago
Yes! I understand your example.
â cwei
15 mins ago
add a comment |Â
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.
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.
answered 35 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
26 mins ago
I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
â bill s
25 mins ago
Yes! I understand your example.
â cwei
15 mins ago
add a comment |Â
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
26 mins ago
I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
â bill s
25 mins ago
Yes! I understand your example.
â cwei
15 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
26 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
26 mins ago
I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
â bill s
25 mins ago
I was showing you that your result is a scalar, irrespective of what Dimensions is telling you.
â bill s
25 mins ago
Yes! I understand your example.
â cwei
15 mins ago
Yes! I understand your example.
â cwei
15 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 has5
terms.â Edmund
29 mins ago
@Edmund Thanks for your explanation! I understand now!
â cwei
14 mins ago