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

Thread Subject: variable help

Subject: variable help

From: Katie

Date: 09 May, 2008 16:05:05

Message: 1 of 3

This is my first time using MATLAB,
I am using this formula to compute sign patterns of 4x4
nilpotent matrices;
A(n+1)=P*A(n)*inv(P) for n=1,2,3,4, where P is a random
matrix and A(1) is the 4x4 jordan. (This formula can be
repeated up to n=4 before sign patterns are duplicated, n
is the number of times that the random matrix (P) can be
used- just a subscript to define the variables). so what I
did was:
A2=P*A1*inv(P)
A3=P*A2*inv(P)
A4=P*A3*inv(P)
A5=P*A4*inv(P)

I want to loop this until all the possible sign patterns
for nilpotent matrices are obtained, changing the random
matrix every 4 times. BUT obviously if I were to loop this
set of equations, for each new P the variables would just
be replaced each time since they are named the same. I have
tried using A(i) or A(n) like in the original equation, but
it is read as multiplication. How do I solve this problem?
or create some sort of subscript system so that the
subscript of the variables change each time.
THANK YOU!

Subject: Re: variable help

From: someone

Date: 09 May, 2008 16:30:18

Message: 2 of 3

"Katie " <kmcdon03@uoguelph.ca> wrote in message
<g01snh$q9j$1@fred.mathworks.com>...
> This is my first time using MATLAB,
> I am using this formula to compute sign patterns of 4x4
> nilpotent matrices;
> A(n+1)=P*A(n)*inv(P) for n=1,2,3,4, where P is a random
> matrix and A(1) is the 4x4 jordan. (This formula can be
> repeated up to n=4 before sign patterns are duplicated, n
> is the number of times that the random matrix (P) can be
> used- just a subscript to define the variables). so what
I
> did was:
> A2=P*A1*inv(P)
> A3=P*A2*inv(P)
> A4=P*A3*inv(P)
> A5=P*A4*inv(P)
>
> I want to loop this until all the possible sign patterns
> for nilpotent matrices are obtained, changing the random
> matrix every 4 times. BUT obviously if I were to loop
this
> set of equations, for each new P the variables would just
> be replaced each time since they are named the same. I
have
> tried using A(i) or A(n) like in the original equation,
but
> it is read as multiplication.

I'm not sure what "read as multiplication" means. If you
want element-by-element multiplication instead of matrix
multiplication replace "*" with ".*" in the above.

> How do I solve this problem?
> or create some sort of subscript system so that the
> subscript of the variables change each time.

The short answer is don't do this! Use cell arrays instead.

You may want to see Q 4.6 in the MATLAB FAQ at:

http:/matlabwiki.mathworks.com/MATLAB_FAQ

 
> THANK YOU!

There is probably some way to use the MATLAB "sum" command
(without using a loop) to do what you want. Try

doc sum

at the MATLAB command promt.

Subject: Re: variable help

From: Roger Stafford

Date: 09 May, 2008 19:39:03

Message: 3 of 3

"Katie " <kmcdon03@uoguelph.ca> wrote in message <g01snh$q9j
$1@fred.mathworks.com>...
> This is my first time using MATLAB,
> I am using this formula to compute sign patterns of 4x4
> nilpotent matrices;
> A(n+1)=P*A(n)*inv(P) for n=1,2,3,4, where P is a random
> matrix and A(1) is the 4x4 jordan. (This formula can be
> repeated up to n=4 before sign patterns are duplicated, n
> is the number of times that the random matrix (P) can be
> used- just a subscript to define the variables). so what I
> did was:
> A2=P*A1*inv(P)
> A3=P*A2*inv(P)
> A4=P*A3*inv(P)
> A5=P*A4*inv(P)
>
> I want to loop this until all the possible sign patterns
> for nilpotent matrices are obtained, changing the random
> matrix every 4 times. BUT obviously if I were to loop this
> set of equations, for each new P the variables would just
> be replaced each time since they are named the same. I have
> tried using A(i) or A(n) like in the original equation, but
> it is read as multiplication. How do I solve this problem?
> or create some sort of subscript system so that the
> subscript of the variables change each time.
> THANK YOU!
-----------
  What kind of "sign pattern" are you looking for? Granted that each of the
matrices A2, A3, A4, A5, etc. you generate from a given P will be nilpotent if
A1 is, but I don't seen any repeating patterns of signs in them.

  However, to answer your question, you could always store your results in a
four-dimensional array as follows. Let nilpotent A and the number of
repetitions N be given.

 P = randn(4,4,N);
 M = zeros(4,4,4,N);
 for k = 1:N
  p = P(:,:,k);
  for m = 1:4
   A = p*A*inv(p);
   M(:,:,m,k) = A;
  end
 end

  Alternatively you could place each 4 x 4 matrix A in a 16 x 1 arrangement in
a three-dimensional 16 x 4 x N array.

 P = randn(4,4,N);
 M = zeros(16,4,N);
 for k = 1:N
  p = P(:,:,k);
  for m = 1:4
   A = p*A*inv(p);
   M(:,m,k) = A(:);
  end
 end

  Note that you should not do this for too large a value of N, because
cumulative round-off errors will gradually erode the condition of A being
nilpotent. That is, the size of elements in A^4 would gradually increase in
size due to accumulating round-off errors. Note also that by chance some of
the p matrices may be nearly singular which will no doubt make the round-
off error situation worse.

Roger Stafford

Tags for this Thread

Everyone's Tags:

sum

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.

Tag Activity for This Thread
Tag Applied By Date/Time
sum someone 09 May, 2008 12:30:34
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