From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Magic Squares Generation Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Description

1. Overview

This example generates the magic square of any given order (or size).

 

2. Description

A magic square is a square array of numbers consisting of the distinct positiveintegers 1, 2, ..., n^2 arranged
such that the sum of the n numbers in anyhorizontal, vertical, or main diagonal line is always the same number.
The Main VI is a program that generates the magic squares of all dimensions. To generate these magic squares, we
develop the three more important methods to generate them. This example shows how to manipulate arrays and how to
switch subVI's based on givenconditions. The three methods togenerate a magic square are:
- De La Loubère's Method.- generates magic squares of odd order, for example: 3, 5, 7, 9, 11…
- X Method.- generates magicsquares of 4*m order, for example: 4, 8, 12, 16, 20…
- LUX Method.- generates magicsquares of order not divisible to 4, for example: 6, 10, 14, 18, 22…

 

3. Requirements

  • NI LabVIEW Base Development System 2012 (or compatible).

 

4. Steps to Implement or Execute Code

  1. Download, unzip and open the compressed example project "Magic Squares Generation LabVIEW 2012
    NIVerified.lvproj".
  2. Open "Main.vi".
  3. Run the Main VI.
  4. Write a positive integer number over 3, in the Order control.
  5. Click Stop to end the application.

 

5. Additional Information or References

Magic Squares Generation LabVIEW 2012 NIVerified.PNG

 

 

 

**The code for this example has been edited to meet the new Community Example Style Guidelines.**

____________________________________________
Carlos Calderón Córdova, Ing.
Universidad Técnica Particular de Loja
Grupo de Control, Automatización y Robótica
Escuela de Electrónica y Telecomunicaciones
Phone: (+593) 7-2570275 ext. 2650
Cell: 098663798
____________________________________________

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
cacalderon
Member
Member
on

I present them my gallery of snapshots of applications developed in
LabVIEW.
I thank to some members of LabVIEW-user groups for their contributions with regard to the design of GUIs.

LabVIEW GUI Gallery Link: http://forums.lavag.org/gallery-user8339-album77.html



____________________________________________
Carlos Calderón Córdova, Ing.
Universidad Técnica Particular de Loja
Grupo de Control, Automatización y Robótica
Escuela de Electrónica y Telecomunicaciones
Phone: (+593) 7-2570275 ext. 2650
Cell: 098663798
____________________________________________
LeoDao
Member
Member
on

I love Magic Square. I cant wait to see these application. Hope we can create application for the Largest Magic square.  I have created variety of magic square using magic square of order 4p and created 6000 by 6000 magic square on a spreedsheet.