
Concept explainers
As early as 650 BC, mathematicians have been composing magic squares, a sequence of n numbers arranged in a square such that all rows, columns, and diagonals sum to the same constant. Used in China, India, and Arab countries for centuries, artist Albrecht Durer’s engraving Melencolia I (year: 1514) is considered the first time a magic square appears in European art. Each row, column, and diagonal of Dürer’s magic square sums to 34. In addition, each quadrant, the center four squares, and the corner squares all sum to 34. The following is an example of a magic square:
Write a program to determine if a series of numbers is indeed a 4 × 4 magic square. Your program should complete the following steps, in this order
- a. Ask the user to enter the proposed magic square in a single input statement (e.g., [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]—note this example is a 4 × 4 matrix, but NOT a magic square). You may assume the user will enter whole numbers; they will not enter either decimal values or text.
- b. Check that all values are positive; ** for-loop or nested for-loop required in the solution. If one or more of the values in the matrix are negative or zero, issue a statement to the command window informing the user of the mistake and ask the user to enter another matrix. This check should be repeated until the user enters a matrix with positive values. This check should work even if the user does not enter a 4 × 4 matrix; it should work regardless of the size of matrix entered.
- c. Check for an arrangement of 4 × 4 If the matrix is not a 4 × 4, issue a statement to the command window informing the user of the mistake, and ask the user to enter another matrix. This check should be repeated until the user enters a 4 × 4 matrix. You may assume the reentered matrix contains only positive values; you do not need to recheck the new matrix for positive values, only for matrix dimensions.
- d. Determine if the matrix is a form of a magic square. The minimum requirement to be classified as a magic square is each row and column sums to the same value. ** for-loop or nested for-loop required in the solution. If this criterion is not met, issue a statement to the command window informing the user they have not entered a magic square and ask the user if they wish to try another magic square. This question can be posed using either a text answer entered by the user (Yes, No) or by using a menu. If the user chooses to run the program again, the entire program starting with step (a) should begin again.
- e. Determine the classification of the magic square using the following requirements:
- 1. If each row and column sums to the same value, the magic square is classified as semi-magic; the summation value is ca led the magic constant. **for-loop or nested for-loop required in the solution.
- 2. If, in addition to criterion 1, each diagonal sums to the same value, the magic square is classified as normal; **for-loop or nested for-loop required in the solution. The use of built-in functions such as diag, flipir, rot90, trace or similar built-in functions is forbidden.
- 3. If, in addition to 1 and 2, the largest value in the magic square is equal to 16, the magic square is classified as perfect.
Format your magic square classification similar to the format shown below. You may choose to format your table differently, but each classification should contain a Yes or No next to each magic square category.
The magic constant for your magic square is 24. The classification for your magic square:
Semi-magic | Normal | Perfect |
Yes | Yes | Yes |
After this table appears, ask users if they wish to try another magic square following the instructions given earlier. A few test cases for you to consider:
- Albrecht Dürer magic square: [16, 3, 2, 13; 5, 10, 11, 8; 9, 6, 7, 12, 4, 15, 14, 1];
- Chautisa Yantra magic square: [7, 12, 1, 14, 2, 13, 8, 11; 16, 3, 10, 5; 9, 6, 15, 4];
- Sangrada Familia church, Barcelona magic square: [1, 14, 14, 4; 11, 7, 6, 9; 8, 10, 10, 5; 13, 2, 3, 15].
- Random magic square: [80, 15, 10, 65; 25, 50, 55, 40; 45, 30, 35, 60; 20, 75, 70, 5];
- Steve Wozniak’s magic square: [8, 11, 22, 1; 21, 2, 7, 12; 3, 24, 9, 6; 10, 5, 4, 23]

Want to see the full answer?
Check out a sample textbook solution
Chapter 20 Solutions
Thinking Like an Engineer: An Active Learning Approach (3rd Edition)
- An Inclining experiment done on a ship thats 6500 t, a mass of 30t was moved 6.0 m transvesly causing a 30 cm deflection in a 6m pendulum, calculate the transverse meta centre height.arrow_forwarda ship 150 m long and 20.5 m beam floats at a draught of8 m and displaces 19 500 tonne. The TPC is 26.5 and midshipsection area coefficient 0.94. Calculate the block, prismatic andwaterplane area coefficients.arrow_forwardA vessel loads 680 t fuel between forward and aft deep tanks. centre of gravity of forward tank is 24m forward of ships COG. centre to centre between tanks is 42 m. how much in each tank to keep trim the samearrow_forward
- Beam of a vessel is 11% its length. Cw =0.72. When floating in SW of relative denisity 1.03, TPC is 0.35t greater than in freshwater. Find the length of the shiparrow_forwardAn inclining experiment was carried out on a ship of 4000tonne displacement, when masses of 6 tonne were moved transverselythrough 13.5 m. The deflections of a 7.5 m pendulurnwere 81, 78, 85, 83, 79, 82, 84 and 80 mm respectively.Caiculate the metacentric height.arrow_forwardA ship of 10 000 tonne displacement has a waterplanearea of 1300 m2. The ship loads in water of 1.010 t/m3 andmoves into water of 1.026 t/m3. Find the change in meandraughtarrow_forward
- A ship of 7000 tonne displacement has a waterplane areaof 1500 m2. In passing from sea water into river water of1005 kg/m3 there is an increase in draught of 10 cm. Find the Idensity of the sea water.arrow_forwardA ship has 300 tonne of cargo in the hold, 24 m forward ofmidships. The displacement of the vessel is 6000 tonne and its centre of gravity is 1.2 m forward of midships.Find the new position of the centre of gravity if this cargo ismoved to an after hold, 40 m from midshipsarrow_forwardSketch and describe how ships are supported in dry dock. When and where does the greatest amount of stresses occur?arrow_forward
- Sketch and desribe a balanced rudder and how it is suspendedarrow_forwardA ship 140 m long and 18 m beam floats at a draught of9 m. The immersed cross-sectionai areas at equai intervais are 5,60, 116, 145, 152, 153, 153, 151, 142, 85 and 0 m2 respectively.Calculate:(a) displacement(b) block coefficient(c) midship section area coefficient(d) prismatic coefficient.arrow_forwardA steamer has waterplane area 1680m2 recorded in water with relative denisty 1.013. Displacement = 1200 t, calculate difference in draught in salwater reltive denisity 1.025.arrow_forward
- Elements Of ElectromagneticsMechanical EngineeringISBN:9780190698614Author:Sadiku, Matthew N. O.Publisher:Oxford University PressMechanics of Materials (10th Edition)Mechanical EngineeringISBN:9780134319650Author:Russell C. HibbelerPublisher:PEARSONThermodynamics: An Engineering ApproachMechanical EngineeringISBN:9781259822674Author:Yunus A. Cengel Dr., Michael A. BolesPublisher:McGraw-Hill Education
- Control Systems EngineeringMechanical EngineeringISBN:9781118170519Author:Norman S. NisePublisher:WILEYMechanics of Materials (MindTap Course List)Mechanical EngineeringISBN:9781337093347Author:Barry J. Goodno, James M. GerePublisher:Cengage LearningEngineering Mechanics: StaticsMechanical EngineeringISBN:9781118807330Author:James L. Meriam, L. G. Kraige, J. N. BoltonPublisher:WILEY





