Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Programming in Matlab

  1. Oct 1, 2011 #1
    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. jcsd
  3. Oct 1, 2011 #2

    uart

    User Avatar
    Science Advisor

    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?
     
  4. Oct 2, 2011 #3
    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"
     
  5. Oct 3, 2011 #4
    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!
     
  6. Oct 3, 2011 #5
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Programming in Matlab
  1. Matlab programming (Replies: 0)

Loading...