Easy way to multiplying standard basis
Mostrar comentarios más antiguos
It seems to be easy, but I am not good at it.
I would like to generate the following matrix that is multiplying of two standard basis:
E_{ij}:= (e_i - e_j)(e_i - e_j)^T
Could any body knows how to write it in few lines?
Thanks
6 comentarios
Azzi Abdelmalek
el 22 de Feb. de 2013
What is T?
Saber
el 22 de Feb. de 2013
Azzi Abdelmalek
el 22 de Feb. de 2013
Editada: Azzi Abdelmalek
el 22 de Feb. de 2013
What is the size of e. Can you provide an example?
Saber
el 22 de Feb. de 2013
Azzi Abdelmalek
el 22 de Feb. de 2013
Post an example with expected result
Azzi Abdelmalek
el 22 de Feb. de 2013
Editada: Azzi Abdelmalek
el 22 de Feb. de 2013
It seems that second Wayne's answer is what you are looking for
Respuestas (3)
Thiru jeyan
el 2 de Mayo de 2017
You can use this method
e=@(k,n) [zeros(k-1,1);1;zeros(n-k,1)]
For an example
>> e(1,3)
ans =
1
0
0>> e(2,5)
ans =
0
1
0
0
0
Wayne King
el 22 de Feb. de 2013
I agree with the comment above that you should provide an example because it's not clear what the size of your problem is or how scalable you want it. For example, are you looking for something as simple as:
E1 = [1 0 0]';
E2 = [0 1 0]';
matrx = (E1-E2)*(E1-E2)';
1 comentario
Wayne King
el 22 de Feb. de 2013
You can just do
I = eye(5);
Each column of I is a standard basis vector
Then,
idx = [3 4];
Is = I(:,idx(1))-I(:,idx(2));
X = Is*Is';
gives you what you want for an example where i=3 and j= 4
2 comentarios
Saber
el 22 de Feb. de 2013
Wayne King
el 22 de Feb. de 2013
so just extract the columns, what is so difficult about that?
Did you look at the Is vector? that is just a column vector.
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!