Thread Subject: double stochastic matrix

Subject: double stochastic matrix

From: Shkelzen

Date: 25 Nov, 2009 14:44:21

Message: 1 of 8

I have to generate in matlab a matrix with main diagonal zero, with row sum equal to 1 and to be symetrix. Please can anybody help me to give the .m file or to give some advices.

Subject: double stochastic matrix

From: Matt

Date: 25 Nov, 2009 15:20:23

Message: 2 of 8

"Shkelzen " <goxhjas@yahoo.com> wrote in message <hejfs5$r8k$1@fred.mathworks.com>...
> I have to generate in matlab a matrix with main diagonal zero, with row sum equal to 1 and to be symetrix. Please can anybody help me to give the .m file or to give some advices.

 A=[0,1;1,0];

Subject: double stochastic matrix

From: Jos (10584)

Date: 25 Nov, 2009 15:26:19

Message: 3 of 8

"Shkelzen " <goxhjas@yahoo.com> wrote in message <hejfs5$r8k$1@fred.mathworks.com>...
> I have to generate in matlab a matrix with main diagonal zero, with row sum equal to 1 and to be symetrix. Please can anybody help me to give the .m file or to give some advices.

Here is some code for starters:

A = rand(4)
q1 = tril(true(4),-1)
q2 = triu(true(4),1)
A(q1) = A(q2) % symmetry
A(eye(4)==1) = 0 % set diagonal to zero

help rand
help diag
help eye
help tril
help triu

hth
Jos

Subject: double stochastic matrix

From: Shkelzen

Date: 26 Nov, 2009 12:31:18

Message: 4 of 8

I gonna try
Thank you!

"Jos (10584) " <#10584@fileexchange.com> wrote in message <hejiar$3q9$1@fred.mathworks.com>...
> "Shkelzen " <goxhjas@yahoo.com> wrote in message <hejfs5$r8k$1@fred.mathworks.com>...
> > I have to generate in matlab a matrix with main diagonal zero, with row sum equal to 1 and to be symetrix. Please can anybody help me to give the .m file or to give some advices.
>
> Here is some code for starters:
>
> A = rand(4)
> q1 = tril(true(4),-1)
> q2 = triu(true(4),1)
> A(q1) = A(q2) % symmetry
> A(eye(4)==1) = 0 % set diagonal to zero
>
> help rand
> help diag
> help eye
> help tril
> help triu
>
> hth
> Jos

Subject: double stochastic matrix

From: Shkelzen

Date: 3 Dec, 2009 10:11:05

Message: 5 of 8

I try the way u tll me, the matrix is OK exept the fact that dont have rows sum equale to 1. Please can u help me make this matrix or is inposible to do a matrix like this.

Thx again !!


"Shkelzen " <goxhjas@yahoo.com> wrote in message <helsem$d7p$1@fred.mathworks.com>...
> I gonna try
> Thank you!
>
> "Jos (10584) " <#10584@fileexchange.com> wrote in message <hejiar$3q9$1@fred.mathworks.com>...
> > "Shkelzen " <goxhjas@yahoo.com> wrote in message <hejfs5$r8k$1@fred.mathworks.com>...
> > > I have to generate in matlab a matrix with main diagonal zero, with row sum equal to 1 and to be symetrix. Please can anybody help me to give the .m file or to give some advices.
> >
> > Here is some code for starters:
> >
> > A = rand(4)
> > q1 = tril(true(4),-1)
> > q2 = triu(true(4),1)
> > A(q1) = A(q2) % symmetry
> > A(eye(4)==1) = 0 % set diagonal to zero
> >
> > help rand
> > help diag
> > help eye
> > help tril
> > help triu
> >
> > hth
> > Jos

Subject: double stochastic matrix

From: Jos (10584)

Date: 3 Dec, 2009 12:49:03

Message: 6 of 8

"Shkelzen " <goxhjas@yahoo.com> wrote in message <hf82rp$khq$1@fred.mathworks.com>...
> I try the way u tll me, the matrix is OK exept the fact that dont have rows sum equale to 1. Please can u help me make this matrix or is inposible to do a matrix like this.

Question 1
if you have two numbers, like [1 2], how would you transform them to make them sum to 1, but still keep the first half the second number?

Question 2
What if you have more numbers [1 2 8 4]?

Subject: double stochastic matrix

From: Shkelzen

Date: 4 Dec, 2009 16:33:22

Message: 7 of 8

"Jos (10584) " <#10584@fileexchange.com> wrote in message <hf8c3v$28r$1@fred.mathworks.com>...
> "Shkelzen " <goxhjas@yahoo.com> wrote in message <hf82rp$khq$1@fred.mathworks.com>...
> > I try the way u tll me, the matrix is OK exept the fact that dont have rows sum equale to 1. Please can u help me make this matrix or is inposible to do a matrix like this.
>
> Question 1
> if you have two numbers, like [1 2], how would you transform them to make them sum to 1, but still keep the first half the second number?
>
> Question 2
> What if you have more numbers [1 2 8 4]?

1.To make the sum 1, one method that i have try is to devide with the row sum. For ex. [1/3,2/3]. Note: The matrix is random.

2. The same method can be use for more numbers.

Subject: double stochastic matrix

From: Jos (10584)

Date: 4 Dec, 2009 22:19:04

Message: 8 of 8

"Shkelzen " <goxhjas@yahoo.com> wrote in message <hfbdki$ms9$1@fred.mathworks.com>...
> "Jos (10584) " <#10584@fileexchange.com> wrote in message <hf8c3v$28r$1@fred.mathworks.com>...
> > "Shkelzen " <goxhjas@yahoo.com> wrote in message <hf82rp$khq$1@fred.mathworks.com>...
> > > I try the way u tll me, the matrix is OK exept the fact that dont have rows sum equale to 1. Please can u help me make this matrix or is inposible to do a matrix like this.
> >
> > Question 1
> > if you have two numbers, like [1 2], how would you transform them to make them sum to 1, but still keep the first half the second number?
> >
> > Question 2
> > What if you have more numbers [1 2 8 4]?
>
> 1.To make the sum 1, one method that i have try is to devide with the row sum. For ex. [1/3,2/3]. Note: The matrix is random.
>
> 2. The same method can be use for more numbers.

Right! Now apply this to each row of the 2D array and you're done. Take a look the function SUM, for-loops and bsxfun.

hth
Jos

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

Contact us at files@mathworks.com