Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Solving Equation

Subject: Solving Equation

From: sumnaray@gmail.com

Date: 23 Nov, 2007 07:47:35

Message: 1 of 9

Hi,

How do I solve for X in equation

X - MXM' = Q

where M, X, and Q are all (n,n) matrix.

Thanks.

Subject: Re: Solving Equation

From: Bruno Luong

Date: 23 Nov, 2007 07:58:58

Message: 2 of 9

sumnaray@gmail.com wrote in message
<d2ea35f2-b295-4b24-a58f-4aa7bf3359ae@s8g2000prg.googlegroups.com>...
> Hi,
>
> How do I solve for X in equation
>
> X - MXM' = Q
>
> where M, X, and Q are all (n,n) matrix.
>
> Thanks.

See thread on similar problem here (Q was identity)

http://www.mathworks.com/matlabcentral/newsreader/view_thread/159258

Bruno

Subject: Re: Solving Equation

From: sumnaray@gmail.com

Date: 23 Nov, 2007 08:02:18

Message: 3 of 9

On Nov 23, 2:58 am, "Bruno Luong" <brunolu...@yahoo.com> wrote:
> sumna...@gmail.com wrote in message
>
> <d2ea35f2-b295-4b24-a58f-4aa7bf335...@s8g2000prg.googlegroups.com>...
>
> > Hi,
>
> > How do I solve for X in equation
>
> > X - MXM' = Q
>
> > where M, X, and Q are all (n,n) matrix.
>
> > Thanks.
>
> See thread on similar problem here (Q was identity)
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/159258
>
> Bruno

Actually, I did try that, but I got
   NaN NaN NaN 0
   NaN NaN NaN 0
   NaN NaN -Inf 0
   NaN NaN 0 1

I did not know what to do after that. :-S

Subject: Re: Solving Equation

From: Bruno Luong

Date: 23 Nov, 2007 08:17:13

Message: 4 of 9

"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fi6181$8dm$1@fred.mathworks.com>...
> sumnaray@gmail.com wrote in message
>
<d2ea35f2-b295-4b24-a58f-4aa7bf3359ae@s8g2000prg.googlegroups.com>...
> > Hi,
> >
> > How do I solve for X in equation
> >
> > X - MXM' = Q
> >
> > where M, X, and Q are all (n,n) matrix.
> >
> > Thanks.
>
> See thread on similar problem here (Q was identity)
>
>
http://www.mathworks.com/matlabcentral/newsreader/view_thread/159258
>

Adapted program:

Bruno
--------------------------

n=5;

M=rand(n);
q=rand(n);
Q=q'*q

Mnlist=cell(1,n);
Mnlist(:)={M'};

BIGM1=blkdiag(Mnlist{:})';
BIGM2=reshape(permute(reshape(BIGM1,n,n,n,n),[2 1 4
3]),n*n,n*n);
X=reshape((eye(n*n)-BIGM1*BIGM2)\Q(:),n,n)
X - M*X*M'


Subject: Re: Solving Equation

From: sumnaray@gmail.com

Date: 23 Nov, 2007 08:28:17

Message: 5 of 9

On Nov 23, 3:17 am, "Bruno Luong" <brunolu...@yahoo.com> wrote:
> "Bruno Luong" <brunolu...@yahoo.com> wrote in message
>
> <fi6181$8d...@fred.mathworks.com>...> sumna...@gmail.com wrote in message
>
> <d2ea35f2-b295-4b24-a58f-4aa7bf335...@s8g2000prg.googlegroups.com>...> > Hi,
>
> > > How do I solve for X in equation
>
> > > X - MXM' = Q
>
> > > where M, X, and Q are all (n,n) matrix.
>
> > > Thanks.
>
> > See thread on similar problem here (Q was identity)
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/159258
>
>
>
> Adapted program:
>
> Bruno
> --------------------------
>
> n=5;
>
> M=rand(n);
> q=rand(n);
> Q=q'*q
>
> Mnlist=cell(1,n);
> Mnlist(:)={M'};
>
> BIGM1=blkdiag(Mnlist{:})';
> BIGM2=reshape(permute(reshape(BIGM1,n,n,n,n),[2 1 4
> 3]),n*n,n*n);
> X=reshape((eye(n*n)-BIGM1*BIGM2)\Q(:),n,n)
> X - M*X*M'

Thanks for your code.

But I am afraid, I still get NaN in my result. I am trying this with

M = [0.5 -0.5 0.5 0; 0 1 0 0; -0.5 -0.5 1.5 0; 0 0 0 0]
and Q as eye(4);

And if you mind me asking, what does [2 1 4 3] mean in BIGM2
expression? I am sorry, I am not very familiar with Matlab.

Thanks again.

Subject: Re: Solving Equation

From: Bruno Luong

Date: 23 Nov, 2007 08:29:57

Message: 6 of 9

Why I bother to symmetrize input Q? Here is the program for
general Q:

n=5; % dimension

% Input
M=rand(n);
Q=rand(n)

% Solve
Mnlist=cell(1,n);
Mnlist(:)={M};
BIGM1=blkdiag(Mnlist{:});
BIGM2=reshape(permute(reshape(BIGM1,n,n,n,n),[2 1 4
3]),n*n,n*n);
X=reshape((eye(n*n)-BIGM1*BIGM2)\Q(:),n,n)

% Check
X - M*X*M'

Subject: Re: Solving Equation

From: Bruno Luong

Date: 23 Nov, 2007 08:38:03

Message: 7 of 9

sumnaray@gmail.com wrote in message

>
> But I am afraid, I still get NaN in my result. I am trying
this with
>
> M = [0.5 -0.5 0.5 0; 0 1 0 0; -0.5 -0.5 1.5 0; 0 0 0 0]

In order the problem to be well-posed, the input M needs to
be a full-rank matrix (inversible). Your matrix isn't. That
is why you get NaN.


>
> And if you mind me asking, what does [2 1 4 3] mean in BIGM2
> expression? I am sorry, I am not very familiar with Matlab.
>

I get an intermediate 4-D array which I want to reshape by
swapping dimensions 1 with 2; and also 3 with 4.

Bruno

Subject: Re: Solving Equation

From: Roger Stafford

Date: 23 Nov, 2007 08:51:05

Message: 8 of 9

sumnaray@gmail.com wrote in message <d2ea35f2-b295-4b24-
a58f-4aa7bf3359ae@s8g2000prg.googlegroups.com>...
> Hi,
>
> How do I solve for X in equation
>
> X - MXM' = Q
>
> where M, X, and Q are all (n,n) matrix.
>
> Thanks.
-------
  This should do it:

U = repmat(M,n,n);
K = floor((n:n^2+n-1)/n);
V = conj(M(K,K));
X = reshape((eye(n^2)-U.*V)\Q(:),n,n);

If M is real-valued, the 'conj' operation is unnecessary.

Roger Stafford

Subject: Re: Solving Equation

From: Bruno Luong

Date: 23 Nov, 2007 08:57:02

Message: 9 of 9

"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fi63hb$2o0$1@fred.mathworks.com>...
> sumnaray@gmail.com wrote in message
>
> >
> > But I am afraid, I still get NaN in my result. I am trying
> this with
> >
> > M = [0.5 -0.5 0.5 0; 0 1 0 0; -0.5 -0.5 1.5 0; 0 0 0 0]
>
> In order the problem to be well-posed, the input M needs to
> be a full-rank matrix (inversible). Your matrix isn't. That
> is why you get NaN.
>

Wait a minute, I'm not certain about this statement. I think
that the condition on M for well-posed is more complex than
that.

Bruno

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics