You are here: Start » Tutorial Exercises » Generating Plots
Generating Plots
Aim:
Create an application that generates plots for the following mathematical functions: * Linear function: y=x * Sine function: y=sin(180 * x) * Quadratic function: y=x * x * Threshold function that returns value 0.5 * sin(x * 360) if x is less than 0.5, otherwise it returns 0.
Function arguments should be provided as Real values.
Input:
The specified parameter range.
Output:
The generated plots displayed in a single preview window.
Hints:
Use the Formulas to calculate function values.
The CreateRealSequence filter should be used to create a series of real values within a specified range.
Use the RealArrayToProfile filter to create a profile that can be used to display a function's plot.
Labeling connections is explained in this article.
Solution (FIS):
-
Add the CreateRealSequence filter to the project and set inCount to 100 and inStep to 0.01. This filter creates an array of real values that will be used as function arguments. Label the outValues output as SequenceValues. You can use that label as an argument in the formula later. It does not have to be connected to the formula.
-
Add an Empty formula to the program. A formula can be easily created by right clicking on the Program Editor Window:
-
To calculate the linear function value, connect SequenceValues with inArray.
-
To calculate the sine function, create a new formula output:
Sine = sin(SequenceValues*180)
-
To calculate the quadratical function, create another formula output:
Quadratical = SequenceValues*SequenceValues
-
Calculation of the threshold function is more complex. First, check if SequenceValues value is greater than 0.5. To do this, operator ?: should be used. The image below shows how to use this operator:
-
Add four RealArrayToProfile filters and connect their inputs to the formula's outputs (in the case of the linear function, refer to point 3.).
-
Display output profiles in a single preview window.
Macrofilter Main is using formula to plot desired functions.
Further Readings
- Formulas - Detailed information about using formulas.