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

AI Thread Summary
The discussion centers around creating a MATLAB program to construct an N×N matrix D, where each element indicates whether the sum of elements of a Pascal matrix of order i equals the sum of elements of a Magic matrix of order j. The user, new to MATLAB, seeks assistance in developing the program for N=100. Initial advice emphasizes the importance of having a clear algorithm before coding. The conversation includes references to existing algorithms for generating Magic squares and a proposed code snippet that attempts to calculate the sums of the matrices. However, the user notes that the results are limited, with only one instance where the sums are equal, specifically D(1,1), leading to confusion about the expected outcomes.
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
 
Physics news on Phys.org
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.
 

Similar threads

Replies
10
Views
3K
Replies
7
Views
2K
Replies
1
Views
2K
Replies
4
Views
3K
Back
Top