Writing MATLAB Program to Construct D and Count Ones for N=100

4 replies · 3K views · last reply
moljka
Messages
2
Reaction score
0
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
 
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?
 
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"
 
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!
 
What I came up with so far is:

Code:
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.