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 solutionChapter 19 Solutions
Thinking Like an Engineer: An Active Approach, Student Value Edition Plus MyLab Engineering with Pearson eText - Access Card Package (4th Edition)
- Please help answer the question shown in the photo. Please explain clearly why the formulas you picked were used, and what the purpose of each number and variable in your calculation represents. Thank you!arrow_forwardEngineering Economy A company has determined the price and the monthly demand of its products are related by the equation D = √775 - p, where p is the price per unit in dollar and D, is the monthly demand. The associated fixed costs are $2,125 per month and the variable costs are $100/ unit. Use this information to answer the following: a)What is the optimal number of units that should be produced and sold each month? b) What is the maximum profit? c)Determine the value of D that represents the break-even point?arrow_forwardtwo cylinders are printed on a 3d printer, with a setting of 40% fill rate. This means that the solid parts of the cylinders at 40% plastic material. Given this, tell me how much plastic material is used to make each of these cylinders. I measured both cylinders in meters and these are the measurements below A) Cylinder 1- Height: 0.042m Radius 2(outer radius): 0.008m Radius 1(inner radius): 0.006m B) Cylinder 2 Height: 0.022m Radius 2(outer radius): 0.008m Radius 1(inner radius): 0.006marrow_forward
- Graph below represents the force on a 12 kg air mass as it passes through a jet engine. Immediately after entering the engine, the force is 9,039 N, and the force tapers linearly to zero once the air reaches the back of the engine 2.3 m later. If the air enters the engine with velocity 252 m/s, what is its exit velocity? (Please answer to the fourth decimal place - i.e 14.3225)arrow_forwardI am unsure of how the equation got to the final result. Can you elaborate on the steps between the last four arrows of this problum?arrow_forwardin the cartesian plane , we have 40 units for vertical forces and 50 units for horizontal forces.what is the angle theta of the planearrow_forward
- hi please solve this question qucikly , i will rate if solved quicklyarrow_forwardhow is it calculated how many numbers in rows or columns should be the sum of when we place integers starting from 1 in a magic square of size NXN? develop the necessary formula depending on N. show that the sum for n=3 will be 15.arrow_forwardIn this calculus proble, a machine design has endpoints of a moveable rod of length 1 meter have coordinates (x,0) and (0,y). The position of the end on the x-axis has a formula given at t is the time in seconds. the formula and this 3 part question is listed ona a separate attachment.arrow_forward
- Hi, The answer is suppose to be 4.36 KN. The picture attached is a hint to the answer according to my professor.arrow_forwardSearch and define the following:(write each required formula - define its variables) 1. Impulse and Momentum2. Work Energy Principle3. Law of conservation of momentumarrow_forwardThe title of our study is "Design and Fabrication of an Agricultural Spraying Attachment for an Autonomous Rover" we need help in the machine design part of our study, specifically Pump selection, battery selection, and center of gravity computation I already sent you the image of the rover Rover weight capacity 35 kilo grams (payload) Rover measurements: Wheel distance - 14.5 inches and 8.5 inches Rover platform size (width & length) 14.4 inches x 10.4 inches Height- 15.8 inches. Water tank selection More or less 25 liters *For tank selection we need to justify the size with the center of gravity, proving that is the maximum dimension or liters of the tank because the center of gravity will be higher making the rover prone to toppling Pump selection *Our sprayer design has two nozzles which splits using a tee splitter, we need to find the size of the pump to obtain the same discharge rate of a normal sprayer. A normal sprayer has a 12V pump and a pressure from 0.2 to 0.45 mpa…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