Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
creating a random matrix based on a set of specifications

Subject: creating a random matrix based on a set of specifications

From: John

Date: 28 Oct, 2010 01:59:04

Message: 1 of 4

Any ideas how i can write a program to create a symmetic nxn matrix with all entries being postive integers, zeros on the diagonal, all the row sums add up to a number S, and the rank is equal to n-1.

Subject: creating a random matrix based on a set of specifications

From: Roger Stafford

Date: 28 Oct, 2010 07:54:04

Message: 2 of 4

"John " <hondacivic0606@yahoo.com> wrote in message <iaald8$71f$1@fred.mathworks.com>...
> Any ideas how i can write a program to create a symmetic nxn matrix with all entries being postive integers, zeros on the diagonal, all the row sums add up to a number S, and the rank is equal to n-1.
- - - - - - - - - - -
  I'll do your problem for n equal to 4. I'm too sleepy for now to attempt a general solution. S must be an even integer greater than or equal to 4, otherwise there is no solution for n = 4.

a = S/2;
b = ceil((a-1)*rand);
c = a-b;
M = [0,a,b,c;a,0,c,b;b,c,0,a;c,b,a,0];
p = randperm(4);
M = M(p,p);

Roger Stafford

Subject: creating a random matrix based on a set of specifications

From: John

Date: 29 Oct, 2010 02:03:04

Message: 3 of 4

Thanks !! could u explain how i would do a 10X10 and 8X8

Subject: creating a random matrix based on a set of specifications

From: Roger Stafford

Date: 29 Oct, 2010 05:55:05

Message: 4 of 4

"John " <hondacivic0606@yahoo.com> wrote in message <iada0o$c83$1@fred.mathworks.com>...
> Thanks !! could u explain how i would do a 10X10 and 8X8
- - - - - - - - -
  I'm afraid not as yet, John. I wasn't even able to solve the 5 x 5 problem after working on it for a while today. The general problem seems like a difficult one. The hard part of the problem is making the rank of the matrix n-1. Otherwise it would be easy to generate solutions.

  Perhaps it would help if you would explain the background behind this problem, including why you need to have the matrix singular. That might set some new ideas in motion.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

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.

Contact us