In every programming language I have used there has always been the option of using mathematical functions to process variables, sometimes a simple mathematical operation can save us from having to write a considerable amount of code to execute the same operation.
It is very true that in LabView we have blocks that perform mathematical operations such as addition, subtraction, division, multiplication among many others, but there comes a time when we want to reduce the blocks used in our designs, in addition to being able to write complex expressions without having to combine blocks to represent them.
For this case we have two blocks that will allow us to execute functions based on mathematical expressions, in this article we will see both blocks and we will apply an example for each one, we will begin with the Expression Node block.
En todo lenguaje de programación que he usado siempre ha existido la opción de usar funciones matemáticas para procesar variables, en ocasiones una simple operación matemática puede ahorrarnos tener que escribir una cantidad considerable de código para ejecutar la misma operación.
Es muy cierto que en LabView disponemos de bloques que realizan operaciones matemáticas como suma, resta, división, multiplicación entre muchas otras, pero llega el momento en el que queremos reducir los bloques usados en nuestros diseños, además de poder escribir expresiones complejas sin necesidad de combinar bloques para que las representen.
Para este caso disponemos de dos bloques que nos permitirán ejecutar funciones basadas en expresiones matemáticas, en este artículo veremos ambos bloques y aplicaremos un ejemplo para cada uno, iniciaremos con el bloque Nodo de Expresión.

As shown in the image, if we place our mouse in the diagram window and right click, then click on Numeric we will find among the available blocks one called Expression Node.
With this block we will be able to process an incoming data by means of a mathematical expression that we will write in the block and the result of this expression will be the output of the block.
To represent the input as a variable we will always use the variable x, so if my expression is x+1 the output will be any value of the input + 1. It is important to note that mathematical operations must always be expressed with the symbol of that operation.
In reality if we have 3x we know that 3 is a coefficient that is multiplying x, we could mistakenly write the expression 3x in the block and it would be taken as an error because if we do not use the symbol that indicates the operation to execute LabView does not understand what we want to do, the correct expression would be 3*x.
We can see a simple example, for this I have created a temperature unit converter, from Fahrenheit to Celsius, on the left I have done it with the blocks of mathematical operations and on the right with the Expression Node.
Tal como señala la imagen, si situamos nuestro mouse en la ventana de diagramas y damos click derecho, luego hacemos clic en Numeric vamos a encontrar entre los bloques disponibles uno llamado Expression Node.
Mediante este bloque podremos procesar un dato entrante mediante una expresión matemática que escribiremos en el bloque y el resultado de dicha expresión sera la salida del bloque.
Para representar la entrada como una variable siempre utilizaremos la variable x, así, si mi expresión es x+1 la salida sera cualquier valor de la entrada + 1. Es importante señalar que las operaciones matemáticas siempre se deben expresar con el símbolo de dicha operación.
En la realidad si tenemos 3x sabemos que 3 es un coeficiente que está multiplicando x, podríamos escribir erróneamente la expresión 3x en el bloque y se tomaría como un error porque si no usamos el símbolo que indica la operación a ejecutar LabView no entiende lo que queremos hacer, la expresión correcta sería 3*x.
Podemos ver un ejemplo sencillo, para ello he creado un conversor de unidades de temperatura, de Fahrenheit a Celsius, en la izquierda lo he hecho con los bloques de operaciones matemáticas y en la derecha con el Expression Node.

Although both models will do the job the expression node one occupies less blocks, besides, if I want to add mathematical operations on the left I will have to add as many blocks as operations I want, however on the right I will continue using a single block and I will only have to add the terms.
The other way to do it is with a structure called Formula Node. It is in the structures folder (the same as while, for, case, flat sequence...).
Aunque ambos modelos harán el trabajo el de expression node ocupa menos bloques, además, si deseo añadir operaciones matemáticas en la izquierda tendre que añadir tantos bloques como operaciones desee, sin embargo en la derecha seguiré usando un solo bloque y solo tendre que añadir los terminos.
La otra forma de hacerlo es con una estructura llamada Formula Node. Está en la carpeta de estructuras (la misma de while, for, case, flat sequence...)

The main difference between Formula Node and Expression Node is that the structure I can add as many inputs and outputs as I want, I can also write more than one mathematical expression, this allows me to relate the same input with different outputs or simply use different inputs for different outputs.
One rule that we must consider is that each input that we create must be connected to an incoming data, another important issue to consider is that all the expressions written inside the structure must end with the symbol ;
For an example of this structure it has occurred to me that the equation of the line that passes through two points and cuts on the y-axis is perfect, that is y = mx+b. I will use two coordinates for the points p1 (x1,y1) and p2(x2,y2), with them I will obtain the value of the slope and the y-cut point.
Then by means of the iteration counter of the for loop I will give different values to x that by means of the formula y=mx+b will modify the value of y, then by means of a graph of x,y we will be able to see the generated line.
La principal diferencia entre Formula Node y Expression Node es que la estructura puedo añadir tantas entradas y salidas como desee, así mismo puedo escribir más de una expresión matemática, esto me permite relacionar una misma entrada con diferentes salidas o simplemente usar entradas distintas para salidas distintas.
Una regla que debemos considerar es que cada entrada que creemos deberá estar conectada a un dato entrante, otro asunto importante a considerar es que todas las expresiones escritas dentro de la estructura deben terminar con el símbolo ;
Para un ejemplo de esta estructura se me ha ocurrido que es perfecta la ecuación de la recta que pasa por dos puntos y corta en el eje de las y, esto es y = mx+b. Usare dos coordenadas para los puntos p1 (x1,y1) y p2(x2,y2), con ellos se obtendrá el valor de la pendiente y el punto de corte en y.
Luego mediante el contador de iteraciones del bucle for le dare diferentes valores a x que mediante la fórmula y=mx+b modificará el valor de y, luego mediante una gráfica de x,y podremos ver la recta generada.

Since I like to test the performance of my designs I am going to enclose everything in a while structure to be able to simulate correctly.
I have joined both designs together to simplify the simulation.
Ya que me gusta comprobar el funcionamiento de mis diseños voy a encerrar todo en una estructura while para poder simular correctamente.
He unido ambos diseños para simplificar la simulación.

Then I have made the order and make-up in the front panel to make the simulation intuitive and fast, I have added knobs to give values to the coordinate points and modified the color of the line in the graph, besides removing the auto scaling both in x and y.
Luego he realizado el orden y maquillaje en el panel frontal para hacer la simulación intuitiva y rápida, he añadido perillas para dar valores a los puntos de coordenadas y modificado el color de la line en el gráfico, además de quitar el auto escalado tanto en x como en y.

For the simulation, first the temperature sensors and their equivalents will be varied to provide the value corresponding to the transformed scale.
Subsequently, the values of x1, y1, x2, y2 are varied to evaluate the behavior of the straight line, in addition the indicator m will give us the value of the slope and b the cut-off point at y.
Para la simulación se van a variar primeramente los sensores de temperatura y sus equivalentes deberán variar para brindar el valor correspondiente a la escala transformada.
Posteriormente se varían los valores de x1, y1, x2, y2 para evaluar el comportamiento de la recta, además el indicador m nos dará el valor de la pendiente y b el punto de corte en y.

I have used the example of the line that passes through two points for being very common and easy to understand, but the structure can be used in more complex operations whose formulas we already know, we only write the formulas in the expression and associate the variables to controls, in this way we can put data in the variables and evaluate the behavior of any system.
If you are a faithful follower of my articles and you like these topics I advise you to add this article to favorites because the method explained here will be used in the future in many other applications and I consider that it is one of the most important blocks that we can learn to use in LabView.
As always, I thank you very much for reading my article, for the support provided and I remain attentive to the comments section.
He usado el ejemplo de la recta que pasa por dos puntos por ser muy comun y facil de comprender, pero la estructura se puede usar en operaciones más complejas cuyas fórmulas ya conocemos, solo escribimos las fórmulas en la expresión y asociamos las variables a controles, de esta forma podemos poner datos en las variables y evaluar el comportamiento de un sistema cualquiera.
Si eres un fiel seguidor de mis articulo y te gustan mucho estos temas te aconsejo añadir este articulo a favoritos ya que el metodo aqui explicado se usara en el futuro en muchas otras aplicaciones y considero que es uno de los bloques mas importantes que podemos aprender a utilizar en LabView.
Como siempre, te agradezco mucho por haber leido mi articulo, por el apoyo brindado y quedo atento a la sección de comentarios.










