Plotting sets of data

  1. Create a set of data points in column form, with a text editor. The left column are the x values and the right are the y values. Save it as points.dat.
    Figure 1


    1.0000 1.0000
    2.0000 1.4142
    3.0000 1.7321
    4.0000 2.0000
    5.0000 2.2361
    6.0000 2.4495
    7.0000 2.6458
    8.0000 2.8284
    9.0000 3.0000
    10.000 3.1623


  2. Drag and drop points.dat onto Kpl to make a plot. If you use these values, you should get the above plot.
  3. You can use Kpl to plot columns of data from KSpread. Save the KSpread spreadsheet as a comma separated value file (*.csv) . Cell B1 contains =sin(A1). Increment this by dragging the cell down the column, by the lower right hand corner.
    Figure 2
  4. Again drag and drop the *.csv file onto Kpl, to make a plot.
    Figure 3

Multiple plots

  1. Add =cos(A1) to the above spreadsheet in cell C1. Increment the values and save the spreadsheet as sincos.csv.
  2. Drag and drop sincos.csv unto Kpl.
  3. Go to Edit -> Items and click on the line "Array file sincos.csv columns 0,1".
  4. Click on Copy to make a copy of that data. Then click on the copied line.
    Figure 4 Figure 5
  5. Choose Edit and change the number in the 'y column' box from 1 to 2.
  6. You can also change the color of the graph, say to red, by selecting the button to the right of Color.
  7. Click on Apply. The new graph, in red, will be superimposed on the original one.
    Figure 6 Figure 7

Curve Fitting

  1. Use the values below to make a plot of data that will be fitted by a second order polynomial (a2x2 + a1x + a0). Save them in a file called fit.dat.

    -1 8.9
    0 4.05
    1 1.07
    2 0.1
    3 1.1
    4 3.88
    5 9.2

  2. Click on Settings and select Configure Autofit....
    Figure 8
  3. In the section labeled y(x), click on the button with ... and select the fkt.so library.
  4. For function, select polynom from the listing under the ... button.
  5. Uncheck the Nonlinear fit box and do check the boxes for Show dialog and Save parameters.
  6. Click on Model and click on Edit. P0 should be 1 and all other entries zero. This will result in a constant weight for all data points.
  7. Click OK to close these dialog boxes.
    Figure 9 Figure 10
  8. In the y(x) box, click on Edit, beside parameter, and check the boxes for p0, p1 and p2. This tells Kpl to fit the curve to a2x2 + a1x + a0. Click OK afterwards.
    Figure 11 Figure 12
  9. Select Autoplot from the Settings drop down menu and click on the box Autofit. Click OK to accept the settings.
  10. Drag and drop, or from the File menu select, fit.dat to make the plot and generate the corresponding curve fit data. Your results should look like these. This shows that the desired "best fit" polynomial is 0.995119x2 - 3.9594x + 4.00071.
    Figure 13
  11. The displayed graph of just the data points should look like the image below.
    Figure 14
  12. Click Apply to generate the fitted curve. It is shown below.
    Figure 15

Plotting Functions

  1. Below is a C program for drawing a damped sine wave:

    #include <math.h>

    double func(double x, const double *p)
    {
      return(exp(-p[0]*x)*sin(p[1]*3.1416*x));
    }

    Save this as fkt.c, in your home directory.
  2. Use the following command to compile the C function and create a shared library:

    gcc -Wall -shared -fPIC -o fkt.so fkt.c -lm

    Do this in a X terminal window (shell).
  3. At the X terminal type:

    nm fkt.so > fkt.def

  4. In Kpl select Edit -> Items -> New -> Frame. Setup the frame box as shown below.
    Figure 16
  5. In Kpl, go to Edit -> Items -> New -> Function and select the fkt.so library from your home directory, for the Library dialog box. For the dialog box Function, select func, the name of our C function.
  6. Click on Edit and put p0 = 0.5 and p1 = 2.0 to graph e-0.5xsin(2*3.1416*x).
    Figure 17 Figure 18
  7. Enter the values for xmin and xmax; xmin = 0 and xmax = 10. Note: If no values are entered here, the defaults of 0 will be used. In that case no graph will be drawn.
    Figure 19