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
Click For Summary

Discussion Overview

The discussion revolves around writing a MATLAB program to construct an N×N matrix D, where the elements are determined by comparing the sums of elements from Pascal and Magic matrices for given orders. The focus includes algorithm development, MATLAB programming, and the specific case of N=100.

Discussion Character

  • Technical explanation
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant requests assistance in writing a MATLAB program for a specific matrix construction problem.
  • Another participant emphasizes the need for an algorithm before coding and inquires about the formulas for the sums of the Pascal and Magic matrices.
  • A third participant shares a logic structure for generating Magic squares in MATLAB, suggesting different cases based on the order of the matrix.
  • A participant expresses a desire to collaborate with another user on the same problem, indicating a shared academic background.
  • A later reply presents a MATLAB code snippet that attempts to construct the matrix D but notes that only one case results in a match between the sums of the Pascal and Magic matrices.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the approach to the problem, and multiple viewpoints regarding the algorithm and coding exist. The discussion remains unresolved regarding the effectiveness of the proposed solutions.

Contextual Notes

There are unresolved aspects regarding the specific definitions and properties of the Pascal and Magic matrices, as well as the assumptions underlying the sums being compared.

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 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K