## Modelica_LinearSystems2.Utilities.Plot.Examples

Demonstrate the usage of the plot functions

### Package Content

Name | Description
--- | ---
plotSine | Plot a sine function in one diagram
plotTwoSine | Plot two sine functions in one diagram
showSinesInVectorDiagrams | Plot sine functions in several diagrams in vector layout
showLegendStyles | Show several vector-diagram plots that demonstrate the various legend options
showMatrixDiagrams | Demonstrate the layout of diagrams in matrix layout
Utilities | Utility functions (usually not of interest for the user)

## Modelica_LinearSystems2.Utilities.Plot.Examples.plotSine

Plot a sine function in one diagram

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Frequency | freqHz | 2 | Frequency of sine wave [Hz]
Damping | damping | 0.8 | Damping coefficient of sine wave [s-1]

### Modelica definition

    function plotSine "Plot a sine function in one diagram"
       input Modelica.SIunits.Frequency freqHz = 2 "Frequency of sine wave";
       input Modelica.SIunits.Damping damping = 0.8
        "Damping coefficient of sine wave";
    protected
       Integer nX = 500;
       Integer nPeriod = 5;
       Real x[nX];
       Real y[nX];
    algorithm
       (x,y) :=Utilities.dampedSine(freqHz, damping, nPeriod, nX);

      Modelica_LinearSystems2.Utilities.Plot.diagram(
        Modelica_LinearSystems2.Utilities.Plot.Records.Diagram(
            curve={Modelica_LinearSystems2.Utilities.Plot.Records.Curve(
              x=x,
              y=y,
              legend="torque1")},
            heading="Bearing friction torque",
            xLabel="w [rad/s]",
            yLabel="[N.m]"));
    end plotSine;

## Modelica_LinearSystems2.Utilities.Plot.Examples.plotTwoSine

Plot two sine functions in one diagram

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Frequency | freqHz1 | 2 | Frequency of sine wave 1 [Hz]
Frequency | freqHz2 | 3 | Frequency of sine wave 2 [Hz]
Damping | damping1 | 0.8 | Damping coefficient of sine wave 12 [s-1]
Damping | damping2 | 0.1 | Damping coefficient of sine wave 2 [s-1]

### Modelica definition

    function plotTwoSine "Plot two sine functions in one diagram"
       input Modelica.SIunits.Frequency freqHz1 = 2 "Frequency of sine wave 1";
       input Modelica.SIunits.Frequency freqHz2 = 3 "Frequency of sine wave 2";
       input Modelica.SIunits.Damping damping1 = 0.8
        "Damping coefficient of sine wave 12";
       input Modelica.SIunits.Damping damping2 = 0.1
        "Damping coefficient of sine wave 2";

    protected
       Integer nX = 500;
       Integer nSymbol = 20;
       Integer nPeriod = 5;
       Real x1[nX];
       Real y1[nX];
       Real x2[nX];
       Real y2[nX];
    algorithm
       (x1,y1) :=Utilities.dampedSine(freqHz1, damping1, nPeriod, nX);
       (x2,y2) :=Utilities.dampedSine(freqHz2, damping2, nPeriod, nX);

      Modelica_LinearSystems2.Utilities.Plot.diagram(
        Modelica_LinearSystems2.Utilities.Plot.Records.Diagram(
            curve={Modelica_LinearSystems2.Utilities.Plot.Records.Curve(
              x=x1,
              y=y1,
              legend="torque1"),
          Modelica_LinearSystems2.Utilities.Plot.Records.Curve(
              x=x2,
              y=y2,
              legend="torque2")},
            heading="Bearing friction torques",
            xLabel="w [rad/s]",
            yLabel="[N.m]"));
    end plotTwoSine;

## Modelica_LinearSystems2.Utilities.Plot.Examples.showSinesInVectorDiagrams

Plot sine functions in several diagrams in vector layout

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Frequency | freqHz1 | 2 | Frequency of sine wave 1 [Hz]
Frequency | freqHz2 | 3 | Frequency of sine wave 2 [Hz]
Damping | damping1 | 0.8 | Damping coefficient of sine wave 12 [s-1]
Damping | damping2 | 0.1 | Damping coefficient of sine wave 2 [s-1]

### Modelica definition

    function showSinesInVectorDiagrams
      "Plot sine functions in several diagrams in vector layout"
       input Modelica.SIunits.Frequency freqHz1 = 2 "Frequency of sine wave 1";
       input Modelica.SIunits.Frequency freqHz2 = 3 "Frequency of sine wave 2";
       input Modelica.SIunits.Damping damping1 = 0.8
        "Damping coefficient of sine wave 12";
       input Modelica.SIunits.Damping damping2 = 0.1
        "Damping coefficient of sine wave 2";

    protected
       Integer nX = 500;
       Integer nSymbol = 50;
       Integer nPeriod = 5;
       Real x1[nX];
       Real y1[nX];
       Real x2[nX];
       Real y2[nX];
       Real x3[nSymbol];
       Real y3[nSymbol];
    algorithm
       (x1,y1) :=Utilities.dampedSine(freqHz1, damping1, nPeriod, nX);
       (x2,y2) :=Utilities.dampedSine(freqHz2, damping2, nPeriod, nX);
       (x3,y3) :=Utilities.dampedSine(freqHz1, damping1, nPeriod, nSymbol);

      Modelica_LinearSystems2.Utilities.Plot.diagramVector({
        Modelica_LinearSystems2.Utilities.Plot.Records.Diagram(
            curve={Modelica_LinearSystems2.Utilities.Plot.Records.Curve(
              x=x1,
              y=y1,
              legend="torque1"),
          Modelica_LinearSystems2.Utilities.Plot.Records.Curve(
              x=x2,
              y=y2,
              legend="torque2")},
            heading="Bearing friction torques",
            yLabel="[N.m]"),
        Modelica_LinearSystems2.Utilities.Plot.Records.Diagram(
            curve={Modelica_LinearSystems2.Utilities.Plot.Records.Curve(
              x=x1,
              y=1.1*y1,
              legend="torque3"),
          Modelica_LinearSystems2.Utilities.Plot.Records.Curve(
              x=x2,
              y=1.2*y2,
              legend="torque4"),
          Modelica_LinearSystems2.Utilities.Plot.Records.Curve(
              x=x3,
              y=y3,
              autoLine=false,
              linePattern=Modelica_LinearSystems2.Utilities.Plot.Types.LinePattern.None,
              lineSymbol=Modelica_LinearSystems2.Utilities.Plot.Types.PointSymbol.Circle)},
            xLabel="w [rad/s]",
            yLabel="[N.m]")});
    end showSinesInVectorDiagrams;

## Modelica_LinearSystems2.Utilities.Plot.Examples.showLegendStyles

Show several vector-diagram plots that demonstrate the various legend options

### Modelica definition

    function showLegendStyles
      "Show several vector-diagram plots that demonstrate the various legend options"
        import Modelica_LinearSystems2.Utilities.Plot.Records;
        import Modelica_LinearSystems2.Utilities.Plot.Types;

    protected
       Real x[2]={0,1};
       Real y1[2]={0,0.5};
       Real y2[2]={0.2,0.7};
       Real y3[2]={0.4,0.9};
       Records.Curve curves[3]=
                           {Records.Curve(
                              x=x,
                              y=y1,
                              legend="curve 1"),
                            Records.Curve(
                              x=x,
                              y=y2,
                              legend="curve 2"),
                            Records.Curve(
                              x=x,
                              y=y3,
                              legend="curve 3")};
    algorithm
      Modelica_LinearSystems2.Utilities.Plot.diagramVector({Records.Diagram(
            curve=curves,
            heading="LegendLocation.Above",
            legendLocation=Types.LegendLocation.Above),Records.Diagram(
            curve=curves,
            heading="LegendLocation.Above, legendHorizontal=false",
            legendHorizontal=false,
            legendLocation=Types.LegendLocation.Above),Records.Diagram(
            curve=curves,
            heading="LegendLocation.Right",
            legendLocation=Types.LegendLocation.Right),Records.Diagram(
            curve=curves,
            heading="LegendLocation.Below",
            legendLocation=Types.LegendLocation.Below)}, Records.Device(
            xTopLeft=0,
            yTopLeft=0,
            diagramWidth=100));

      Modelica_LinearSystems2.Utilities.Plot.diagramVector({Records.Diagram(
            curve=curves,
            heading="LegendLocation.TopLeft",
            legendLocation=Types.LegendLocation.TopLeft),Records.Diagram(
            curve=curves,
            heading="LegendLocation.TopRight, legendHorizontal=false",
            legendHorizontal=false,
            legendLocation=Types.LegendLocation.TopRight),Records.Diagram(
            curve=curves,
            heading="LegendLocation.BottomLeft",
            legendLocation=Types.LegendLocation.BottomLeft),Records.Diagram(
            curve=curves,
            heading="LegendLocation.BottomRight",
            legendLocation=Types.LegendLocation.BottomRight)}, Records.Device(
            xTopLeft=105,
            yTopLeft=0,
            diagramWidth=100));

    end showLegendStyles;

## Modelica_LinearSystems2.Utilities.Plot.Examples.showMatrixDiagrams

Demonstrate the layout of diagrams in matrix layout

### Modelica definition

    function showMatrixDiagrams
      "Demonstrate the layout of diagrams in matrix layout"
        import Modelica_LinearSystems2.Utilities.Plot.Records;
        import Modelica_LinearSystems2.Utilities.Plot.Types;

    protected
       Real x[2]={0,1};
       Real y1[2]={0,0.5};
       Real y2[2]={0.2,0.7};
       Real y3[2]={0.4,0.9};
       Records.Curve curves[3]=
                           {Records.Curve(
                              x=x,
                              y=y1,
                              legend="curve 1"),
                            Records.Curve(
                              x=x,
                              y=y2,
                              legend="curve 2"),
                            Records.Curve(
                              x=x,
                              y=y3,
                              legend="curve 3")};
    algorithm
      Modelica_LinearSystems2.Utilities.Plot.diagramMatrix(fill(
            Records.Diagram(curve=curves),
            5,
            3), Records.Device(diagramWidth=80));

    end showMatrixDiagrams;