Evaluation of matrix element of a linear differential matrix equation by constrained least square fitting

Asked by Sudipta Sinha

Sudipta Sinha (view profile)

on 7 Aug 2013
Accepted Answer by Richard Brown

Richard Brown (view profile)

Hi All,
I was trying to evaluate the matrix coefficient by the method of constrained least square fitting. The linear matrix differential equation looks like X'=AX, where X' and X are two vectors and A is matrix. Moreover, there is a constraint on diagonal matrix element and which is a(i,i)=-Sum(i/=j)a(i,j). The elements of X' and X vectors are known. I was trying to use MATLAB to do that. But I didn't figure out which figure out which MATLAB function is suitable for that. Can you guide me in this regard.
Thanks in advance Sudipta

Tags

Answer by Richard Brown

Richard Brown (view profile)

on 7 Aug 2013

Assuming you have multiple X and X' vectors that you're trying to fit your matrix to, your problem can be posed as a constrained linear least squares problem in the entries of A, which can be solved using lsqlin

Richard Brown

Richard Brown (view profile)

on 7 Aug 2013
Please reply to answers with comments, not further answers. I won't write you a script to do it, but it's pretty straightforward - I suggest you do it with pen and paper first.
Treat the entries of A as a vector comprised of its columns stacked together. Each row of each X' = A*x equation is linear in the entries of A. It just takes a bit of thought and messing around to construct the right matrices.
The diagonal sum constraint is an equality constraint.
Sudipta Sinha

Sudipta Sinha (view profile)

on 7 Aug 2013
Thanks for your continuing help. I am facing a confusion. The function lsqlin function evaluates the values of X. But I need the matrix elements. The arguments of the lsqlin function are A, X' and the constraint equation and it evalutes the X vector. In my case the matrix is unknown and need to evaluate that. So what will be the format of matlab lsqlin function. Another thing if Sum a(i,j)=0 then the constraint equation look like a11+a12+....a1n=0 and so on for other rows. But what will be the matlab lsqlin function format of this constraint equation.
Richard Brown

Richard Brown (view profile)

on 7 Aug 2013
The vector that you get out from lsqlin will be the columns of A, stacked into a vector. The matrix Ahat that you provide to lsqlin will be big (it's not A). For example, assuming your vectors have m entries and A is square, the first m rows of the matrix Ahat you provide to lsqlin will be
tmp = repmat({x1},m,1);
Ahat(1:m,:) = blkdiag(tmp{:})
where x1 is your first X vector. Likewise the first m entries of the RHS will be xp1 (your first X' vector)