This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Modify the main diagonal of a matrix

Tags: None
(comma "," separated)
bobo01
Registered Member
Posts
10
Karma
0

Modify the main diagonal of a matrix

Tue Apr 07, 2015 11:36 am
Hello,

How do you modify only the main diagonal of a matrix? I can see functions for extracting the main diagonal but is there a way to do this by just adding a small number to it. I am trying to add some Tikohnov Regularisation to my matrix.

Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
For scalar to vector addition, move to the array world, e.g.:
Code: Select all
MatrixXd mat;
// ...
mat.diagonal().array() += 1.2345;


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]