Bubblesoft Maths Library: Demonstration Software

The Bubblesoft Maths library covers a wide range of operations. This demonstration software samples a tiny part, and is intended to give a feel for the quality and ease of use of the library, rather than to represent the full capabilities included.

If you are fortunate enough to be using the `LINUX' operating system on an x86 processor, you will be able to use the example executable programs (ELF format). Otherwise, you can still try out the software by compiling the source code extracts provided.

Solution of a matrix equation

Program matsol solves a matrix equation
A x = y
for x (a vector) given A (a matrix) and y (a vector). A may have more rows than columns (i.e. the problem may be overdetermined), in which case a least-squares solution is produced.

The program uses a library routine which solves the equation using Givens rotations to make A upper-triangular then back-substitution to find x.

Usage

At a command prompt, type
matsol < matsol.dat
to read data from file matsol.dat. The solution is written to standard output.

Input data

ASCII (text), free-format:
number_of_rows number_of_columns
For each row i in A:
   For each column j in A:
      A(i,j)
For each element i of y:
   y(i)
e.g.
2 2
1.5 2.3
-5.8 9.0
-1.2
7.3

Files

Fitting data with a polynomial

Program polyfit fits a set of (x,y) data points with a polynomial
y = sumi=1n cixi-1.
Each point has a weighting, which can reflect the uncertainty in the data (e.g. setting the weight w to 1/s where s is the standard deviation for the point).

The program uses a library routine which performs the fit by building an overdetermined matrix describing the problem, and solving to find a least-squares solution for the coefficients ci.

The program can also plot the data and polynomial fit, using calls to the Bubblesoft Graphics Library. The executable provided calls the X-Windows version of this library.

If you're interested in details, the sample data was generated by taking the function
y = 0.56 - 2.8 x + 3.5 x2
of a set of x-values, and adding random noise with uniform distribution from 0 to 0.2.

Usage

At a command prompt, type
polyfit < polyfit.dat
to read data from file polyfit.dat. The coefficients ci and residue are written to standard output, and a window opened to display the data and fit if X-Windows is running.

Input data

ASCII (text), free-format:
number_of_data_points
For each data point:
   x y weight
number_of_polynomial_coefficients
xmin xmax ymin ymax
number_of_line_segments
where e.g.
5
0.5 0.6
0.6 0.75
0.7 0.9
0.8 0.89
0.9 0.95
3
0.0 1.0 0.0 1.0
100

Files

Additional source code

If you wish to compile the demonstration programs yourself, you may need the following files:

To compile the programs:

  1. Put all source code in a single directory.
  2. If you have access to the Bubblesoft maths and graphics libraries, make sure that the Makefile searches for them in the correct directory. Otherwise, you will only be able to build the `no library' versions, matsol_nolib and datafit_nolib.
  3. Type make (or make program_name, where program_name is one or more of the program names).