tags:

views:

88

answers:

1

How can I create the following matrix

1  0  0  0  0 
k1 1  0  0  0 
k2 k1 1  0  0
k3 k2 k1 1  0
k4 k3 k2 k1 1
+9  A: 

Use TOEPLITZ.

E.g.

vector = [1 2 3 4 5]; %# replace this with values for [1 k1 k2 k3 k4]
out = toeplitz(vector,[1 0 0 0 0])
out =
     1     0     0     0     0
     2     1     0     0     0
     3     2     1     0     0
     4     3     2     1     0
     5     4     3     2     1

EDIT

my vector is [k1 k2 k3 k4 k5], how can i apply tril or toeplitz?

Using @gnovice's more convenient formulation, you use

yourVector = [k1 k2 k3 k4 k5];
tril(toeplitz([1 yourVector(1:4)]))
Jonas
thank u very much
blue_arkedia
Please consider accepting the answer if you find it useful.
Jonas
The function [TRIL](http://www.mathworks.com/access/helpdesk/help/techdoc/ref/tril.html) could also be used to create a slightly different form of the above solution: `out = tril(toeplitz([1 k1 k2 k3 k4]));`
gnovice
my vector is [k1 k2 k3 k4 k5], how can i apply tril or toeplitz?
blue_arkedia
the function tril(toeplitz([k1 k2 k3 k4 k5])) givesk1 0 0 0 0k2 k1 0 0 0k3 k2 k1 0 0k4 k3 k2 k1 0k5 k4 k3 k2 k1BUT the matrix i want is1 0 0 0 0k1 1 0 0 0 k2 k1 1 0 0k3 k2 k1 1 0 k4 k3 k2 k1 1
blue_arkedia
Oh, ok. See my update.
Jonas
thank you very much it is wa i wanted
blue_arkedia

related questions