Programming in Matlab

1. Oct 1, 2011

moljka

Hello,

I need help with the following:

"Let D be an N×N matrix. The element dij (i=1,…,N;j=1,…,N) of D is 1 if the sum of all the elements of the Pascal matrix of order i equals the sum of all the elements of Magic matrix of order j, and 0 otherwise.
Write a Matlab programme that constructs D and that counts the number of ones in D for N is 100."

I am new to matlab programming (this will be the first time writing a matlab programme). Please help me out.

Kind regards,

Moljka

2. Oct 1, 2011

uart

Well before you even start thinking about matlab (or code of any type) you need an algorithm.

Do you have a formula for the sum of a (triangular form?) Pascal matrix and for a (normal?) Magic matrix?

3. Oct 2, 2011

moljka

hello,

The matlab guide contains an example magic squairs algorithm:

"The logic of the magic squares algorithm can also be described by:

switch (rem(n,4)==0) + (rem(n,2)==0)
case 0
M = odd_magic(n)
case 1
M = single_even_magic(n)
case 2
M = double_even_magic(n)
otherwise
error('This is impossible')
end"

4. Oct 3, 2011

FFMSmit

My guess is you are an Economics student @ the Rijksuniversity of Groningen.

I am dealing with the exact same problem. Can you add me on facebook (Frank Smit, Groningen ) or MSN: ffmsmit@hotmail.com or skype: fibofranky .

Perhaps we can work it out together!

5. Oct 3, 2011

FFMSmit

What I came up with so far is:

Code (Text):
N = 100
for i = 1:N
for j = 1:N
p(i) = sum(sum(pascal(i)));
m(j) = sum(sum(magic(j)));

if p(i) == m(j)
D(i,j) = 1
else
D(i,j) = 0
end

end
end
However... There is only 1 case where the sum of elements of pascal = magic, which is in D(1,1). Confusing.