Easy way to multiplying standard basis

조회 수: 25 (최근 30일)
Saber
Saber 2013년 2월 22일
답변: Thiru jeyan 2017년 5월 2일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 22일
Post an example with expected result
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 22일
편집: Azzi Abdelmalek 2013년 2월 22일
It seems that second Wayne's answer is what you are looking for

댓글을 달려면 로그인하십시오.

답변 (3개)

Thiru jeyan
Thiru jeyan 2017년 5월 2일

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
Wayne King 2013년 2월 22일
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
Saber
Saber 2013년 2월 22일
편집: Saber 2013년 2월 22일
Let's our dimension is n=5. Now in this dimension we have five standard basis which all together build identity matrix I up. e_i shows this unit vectors(columns of I) that in i'th position is 1 and other entries are all zero. for example
e_3= 0
0
1
0
0
now I want to build up a routine way to create this vectors and label them as the position of 1's.
I hope that now it is clear a bit.

댓글을 달려면 로그인하십시오.


Wayne King
Wayne King 2013년 2월 22일
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
Saber
Saber 2013년 2월 22일
The out put is too strange:
X =
0 0 0 0 0
0 0 0 0 0
0 0 1 -1 0
0 0 -1 1 0
0 0 0 0 0
I need to separate matrix
I =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
as unit indexed vectors
1 0 0 0 0
0 1 0 0 0
e_1= 0 e_2= 0 e_3= 1 e_4= 0 e_5= 0
0 0 0 1 0
0 0 0 0 1
Wayne King
Wayne King 2013년 2월 22일
so just extract the columns, what is so difficult about that?
Did you look at the Is vector? that is just a column vector.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by