Plotting Continuous Functions with LabVIEW

 

          Suppose you want to plot a function, e.g. cos(t), then a String Control can be used to input the function and a Waveform Graph can be used to show the plot. Recall computers cannot deal with functions the way you do, it does not internally store a picture of the continuous cosine function, but it can generate a discrete sequence of numbers that when plotted resembles the cosine function, to a certain degree of precision. In one phrase, computers can only deal with discrete numbers.

            Suppose you want to plot a function between t1 and t2 using N+1=101 points then a sequence of 101 values for t needs to be generated that starts at t1, ends at t2, with increments of (t2-t1)/N=(t2-t1)/100. For example, let’s say t1=0 and t2=4, then the increment is 0.04. This can be done with a FOR LOOP with i running from 0 to N as shown in the attached diagram (notice that in the attached diagram, N=16, i.e. 17 points are generated between t1=0 and t2=4). Then the input function needs to be evaluated at each of these N+1 values by using the built-in EVALUATION OF SINGLE-VARIABLE ARRAY that can be found under G Math-Parsers VI or Advanced Parsing Formulas. Once placed in the diagram, as you approach this icon with the wiring tool, definitions of each of its 5 terminals will be shown, the ones we are interested in are the input function (upper left), the input x values (middle left), and the output y values (upper right, which are the values of the function, as specified by input function, at the input x values). Finally the information that need to be bundled into the waveform graph (using BUNDLE under Cluster) are the initial point t1, the increment (t2-t1)/N, and the sequence of the output y values from Eval Single-Variable Array. The Bundle initially shows only two input terminals but you can add one more by right click on these terminals and do add input.

            Once the cos(t) is entered in the String Control and the program is run, you should obtain a plot of the cosine function as shown in the front panel below.

            Then you should try, by using different number of points, e.g. between 4 and 400, to determine what is the smallest number of points needed to get a good enough plot of the function (you do not want to waste computer resources in a large program since you want to wait the least for a good-enough result)

.