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

  • Context: MATLAB 
  • Thread starter Thread starter moljka
  • Start date Start date
  • Tags Tags
    Matlab Programming
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 3K views
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.