Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matrix based on vector and diagonal elements=1 using matlab

Tags:

matlab

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
like image 825
blue_arkedia Avatar asked Jan 21 '23 16:01

blue_arkedia


1 Answers

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)]))
like image 92
Jonas Avatar answered Mar 15 '23 23:03

Jonas