MATLAB help anyone?

magomago

Lifer
Sep 28, 2002
10,973
14
76
man i wished i paid more attention in linear algebra... ;)


okay i have this matrix:

1 0 0 0 0
-1 1 0 0 0
-1 -1 1 0 0
-1 -1 -1 1 0
-1 -1 -1 -1 1

created by the code tril(-1*ones(5,5),-1)+eye(5)


i want to get to



1 0 0 0 1
-1 1 0 0 1
-1 -1 1 0 1
-1 -1 -1 1 1
-1 -1 -1 -1 1

anyone have an idea?
 

qbek

Member
Mar 12, 2005
110
0
0
Why don't you just define the matrix you want, without calculating it, just type it in.
For a simple code, for a general n you can use:

[zeros(n,n-1),[ones(n-1,1);0]]+tril(-1*ones(n,n),-1)+eye(n)

Does it help?