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:
specific matrix

Subject: specific matrix

From: alex

Date: 18 Mar, 2010 21:32:04

Message: 1 of 5

hey

i need to create a matrix that has three properties

The matrix A of order n (to be decided by the user) should have the following properties:
1) for i not= j the element in the i-th row and j-th column, written in matrix terms as A(i; j),
should have the value either 1 or 0

2) A(i; j) = A(j; i), i.e the matrix A is symmetric.

3) the diagonal element in the i-th row and i-th column, written in matrix terms as A(i; i),
should be such that the sum of the elements of any row should add up to zero.

can anyone help?

Subject: specific matrix

From: us

Date: 18 Mar, 2010 21:48:04

Message: 2 of 5

"alex " <av90@le.ac.uk> wrote in message <hnu64k$lin$1@fred.mathworks.com>...
> hey
>
> i need to create a matrix that has three properties
>
> The matrix A of order n (to be decided by the user) should have the following properties:
> 1) for i not= j the element in the i-th row and j-th column, written in matrix terms as A(i; j),
> should have the value either 1 or 0
>
> 2) A(i; j) = A(j; i), i.e the matrix A is symmetric.
>
> 3) the diagonal element in the i-th row and i-th column, written in matrix terms as A(i; i),
> should be such that the sum of the elements of any row should add up to zero.
>
> can anyone help?

what have YOU done so far to solve YOUR homework(?)...

us

Subject: specific matrix

From: alex

Date: 18 Mar, 2010 21:59:20

Message: 3 of 5

"us " <us@neurol.unizh.ch> wrote in message <hnu72k$6th$1@fred.mathworks.com>...
> "alex " <av90@le.ac.uk> wrote in message <hnu64k$lin$1@fred.mathworks.com>...
> > hey
> >
> > i need to create a matrix that has three properties
> >
> > The matrix A of order n (to be decided by the user) should have the following properties:
> > 1) for i not= j the element in the i-th row and j-th column, written in matrix terms as A(i; j),
> > should have the value either 1 or 0
> >
> > 2) A(i; j) = A(j; i), i.e the matrix A is symmetric.
> >
> > 3) the diagonal element in the i-th row and i-th column, written in matrix terms as A(i; i),
> > should be such that the sum of the elements of any row should add up to zero.
> >
> > can anyone help?
>
> what have YOU done so far to solve YOUR homework(?)...
>
> us

hey us

well iv got this so far

n=input('Enter a positive integer');
m=input('Enter a positive scalar');
I=eye(n);
a=round(rand(1))
b=round(rand(1))
c=round(rand(1))
d=round(rand(1))
e=round(rand(1))
f=round(rand(1))
g=round(rand(1))
m1=-(a+b+c)
m2=-(a+d+e)
m3=-(d+b+f)
m4=-(a+b+c)
A=[m1 a b c ; a m2 d e ; b d m3 f ; c e f m4]
W=I+(m*A)


W=x1
for (k=1:10);
    x1=W.*x1;
end

but this is purely for a 4 x 4 matrix i want to be able to create a similiar matrix but with any size of square matrix without typing this out an infinite amount of times, is there a special loop i can use that creates this random matrix?

Subject: specific matrix

From: alex

Date: 18 Mar, 2010 22:09:04

Message: 4 of 5

hey us

well i've got this so far:

n=input('Enter a positive integer');
m=input('Enter a positive scalar');
I=eye(n);
a=round(rand(1))
b=round(rand(1))
c=round(rand(1))
d=round(rand(1))
e=round(rand(1))
f=round(rand(1))
g=round(rand(1))
m1=-(a+b+c)
m2=-(a+d+e)
m3=-(d+b+f)
m4=-(a+b+c)
A=[m1 a b c ; a m2 d e ; b d m3 f ; c e f m4]
W=I+(m*A)


W=x1
for (k=1:10);
    x1=W.*x1;
end

but this is only for a 4x4 matrix i was wondering if there was a specific loop i could use that will allow me to combine commands like pascal, rand, round and sum so that i don't have to write this out infinitely. I'm trying to teach myself how to use matlab but books can only get you so far before you have to consult someone to help explain something i don't get.

Subject: specific matrix

From: Sadik

Date: 18 Mar, 2010 22:47:02

Message: 5 of 5

Hi Alex,

You can do this:

A = round(rand(n));
upperTriangle = triu(A);
symmetricMatrix = upperTriangle + upperTriangle';
A = symmetricMatrix + diag(-sum(symmetricMatrix,2));

Please look at the output of each line to understand what it is doing.

Best.

Tags for 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