Quadratic root calculation in LabView : tutorial 26




In this tutorial I will tell you how to calculation roots of a quadratic equation using LabView. Quadratic roots calculation is one of the most easiest but hectic task near me. In this tutorial I will help you design a VI that will take input as the coefficients of a quadratic equation and at the output; it will return you with the roots of the equation you gave as input. At the end of the tutorial you are provided with an exercise to do it by yourself, and in the next tutorials I will assume that you have done those exercises and I will not explain the concept regarding them.




Quadratic root calculation in LabView example

  • I will now help you design a VI that will take three co-efficient of a quadratic equation as an input and at the output return the roots of the equation. Create a VI as I have explained in tutorial 1 and save it for future use. On the front panel click right and from the Control palette select numeric and then select control  as shown in the figure below,Quadratic root calculation in LabView

Figure 1: Numeric control placement

  • Place three similar indicators are name them as a, b and c, because a simple quadratic equation have only three co-efficient. See the figure below,Quadratic root calculation in LabView

Figure 2: Input controls

  • Now from the control palette on the front panel select numeric and then select indicator as shown in the figure below,Quadratic root calculation in LabView

Figure 3: Numeric indicator placement




  • Place two indicators of type numeric and name them as x1 and x2 because a quadratic equation has only two roots. Refer to the figure below,Quadratic root calculation in LabView

Figure 4: Output indicator

  • LabView have a structure named as formula node, in which you can write a code in mathscript. On the function block click right and from the function palette select structures and then select formula node as shown in the figure below,Quadratic root calculation in LabView

Figure 5: Formula node placement

  • Place the block in between the input controls and the output indicators. Right click on the left side of the formula node i.e. on the input side and from the dropdown, select Add input  as shown in the figure below,Quadratic root calculation in LabView

Figure 6: Adding input node

  • Similarly, on the right side of the formula node i.e. on the output side of the node click right and from the dropdown menu select Add output as shown in the figure below,Quadratic root calculation in LabView

Figure 7: Adding output node

  • At the input side create three nodes because of three inputs co-efficient and at the output side create two nodes as we have two roots as the output, as shown in the figure below.Quadratic root calculation in LabView

Figure 8: Inputs and outputs

  • Connect the input nodes to the input controls and the output nodes to output indicators and name the variables, as shown in the figure below,Quadratic root calculation in LabView

Figure 9: Connections

  • Don’t forget to align each group of block according to the orientation as I have done, and I have explained in previous tutorials.
  • Now inside the formula node, write a mathscript code to calculate the roots of a quadratic equation i.e. As shown in the figure below,Quadratic root calculation in LabView

Figure 10: Formula code

  • If you are not familiar with any of the command in LabView simple open the built in help window of LabView see the detailed description of the command or block about which you want to know.
  • The nodes you created on the input and output side of the formula node will store the value of the controls you connected to them or for the output case they will display the value from the formula node to the output indicator.
  • But, where will it store the value from the input control?? We have to name the node with a specific variable in which it will store the value from the input control and will use that dummy variable inside the formula node.
  • Similar is the case with the output nodes, all the values assigned to any dummy variable inside the formula node i.e. x1 and x2 in our case will have one output node assigned to it.
  • No of output nodes must be equal to the number of assignment operator used inside the formula node and we have to name output nodes too according to the dummy variable inside the formula node as shown in the figure below,Quadratic root calculation in LabView

Figure 11: Naming of the node.

  • On the front panel give specific input values to the input controls you created in the start and run the VI. The output indicators will display the roots of the equation formed by using the input variables as shown in the figure below,Quadratic root calculation in LabView

Figure 12: Output of the VI

  • The VI we designed here will calculate only the real roots of the quadratic equation

Exercise:

  • Use the knowledge you have gained so far and try to generalize the above VI for finding out imaginary roots too.

<<Previous tutorial                                              Next tutorial>>




Add Comment