Dew Research
Search entire site:
  Home| Products | Order | Downloads | FAQ | Support | About us
Introducing MtxVec 2.0 the number crunching library is back with dot Net support.More

Develop within .NET and deliver the code speed of assembler.
• Comprehensive and fast numerical math library
• support for VS.NET, Borland Delphi and C++ Builder
• statistical and DSP add-ons

 
MtxVec
Screenshots
MtxVec
Visit our comprehensive Screenshot Gallery.
Applications
MtxVec for mission critical applications where complex real time data processing is needed. Ten times faster than conventional programming.
MtxVec applications
Testimonials
"Using MtxVec 2, with its SSE2 support, I see about a x4 speed improvement over traditional x87 assembler when running on my Pentium 4 notebook!"

Matthew Wormington, Bede Corporation
More Testimonials
FFT properties 5.0
Borland Delphi Microsoft Dot .Net
About

Nist logo Case study: Load Cell Calibration

NIST info: This example illustrates the construction of a linear regression model for load cell data that relates a known load applied to a load cell to the deflection of the cell. The model is then used to calibrate future cell readings associated with loads of unknown magnitude. Full description can be found here.

Data: The data collected in the calibration experiment consisted of a known load, applied to the load cell, and the corresponding deflection of the cell from its nominal position. Forty measurements were made over a range of loads from 150,000 to 3,000,000 units. The data were collected in two sets in order of increasing load. The systematic run order makes it difficult to determine whether or not there was any drift in the load cell or measuring equipment over time. Assuming there is no drift, however, the experiment should provide a good description of the relationship between the load applied to the cell and its response. Full dataset is available here.


In this example we will follow the suggested steps, listed at NIST pages. As suggested, we will use linear and quadratic polynomial to perform fitting and estimating.

1) Read in the data: For regression we will use Polynoms PolyFit routine. First we have to create necessary vectors and populate them.

2) Plot the y=y(x) chart to get an idea about the fit model. For this, you can use the MtxVecTee.DrawValues method. These two steps can be acomplished by the following code:

Delphi
Uses MtxVec, Polynoms, Math387, MtxVecTee, MtxExpr;


procedure FitModel;
var  x,y, residuals, coeffs, ycalc: Vector;
  rss: TSample;
begin
  nlr := TMtxNonLinReg.Create(nil);
  Chart1.FreeAllSeries;
  Chart1.AddSeries(TLineSeries.Create(Chart1));
  try
    x.LoadFromFile('xdata.vec');
    y.LoadFromFile('ydata.vec');
    DrawValues(x,y,Chart1.Series[0]);
BCB
#include "MtxVecCpp.h"
#include "Polynoms.hpp"
#include "Math387.hpp"
#include "MtxVec.hpp"
#include "MtxVecTee.hpp"


void FitModel(void);
{
  Vector x,y,residuals,coeffs,ycalc;
  Chart1->FreeAllSeries();
  Chart1.AddSeries(new TLineSeries(Chart1));
  try
  {
    x->LoadFromFile("xdata.vec");
    y->LoadFromFile("ydata.vec");
    DrawValues(x,y,Chart1->Series[0],0,1,false);
C#
using Dew.Math;
using Dew.Math.Units;
using Dew.Stats.Units;
using Dew.Stats;


namespace Dew.Tests
{
  private void FitModel()
  {
    Vector x = new Vector(0);
    Vector y = new Vector(0);
    Vector residuals = new Vector(0);
    Vector ycalc = new Vector(0);
    Vector coeffs = new Vector(0);
    tChart1.Series.Clear();
    tChart1.Series.Add(new Steema.TeeChart.Styles.Line(tChart1.Chart));
    try
    {
      x.LoadFromFile("xdata.vec");
      y.LoadFromFile("ydata.vec");
      MtxVecTee.DrawValues(x, y, tChart1[0],0,1,false);

Plotting the data indicates that the hypothesized, simple relationship between load and deflection is reasonable. The plot indicates that a straight-line model is likely to fit the data. It does not indicate any other problems, such as presence of outliers or nonconstant standard deviation of the response.

3) Perform simple LQ linear regression on data: With just few lines of code, least squared linear regression is applied to x,y data:

Delphi
  // Perform linear regression
  PolyFit(x,y,coeffs,1);
  // Calculate residuals
  PolyEval(x,coeffs,ycalc);
  residuals.Sub(ycalc,y);
  rss := residuals.SumOfSquares;
BCB
  // perform linear regression
  PolyFit(x,y,coeffs,1);
  // calculate residuals
  PolyEval(x,coeffs,ycalc);
  residuals->Sub(ycalc,y);
  double rss = residuals->SumOfSquares();
C#
  // Perform linear regression
  Polynoms.PolyFit(x,y,coeffs,2);
  // Calculate residuals
  Polynoms.PolyEval(x,coeffs,ycalc);
  residuals.Sub(ycalc,y);
  double rss = residuals.SumOfSquares();

Now that we have estimated y(x) values and residuals, we can use MtxVecTee.DrawValues method to check the goodnes of out model selection. Plotting several charts reveals the linear model is not a very good choice. Next we try to fit a higher order polynomial to the data (quadratic polynom). We only have to change the PolyFit(x,y,coeffs,1) to PolyFit(x,y,coeffs,2) and repeat the procedure.

Additional things to try :

  • Plot data, fitted data and residuals by using MtxVecTee.DrawValues routine.
  • Plot normal probability plot of residuals.
  • Plot histogram of residuals.
  • Compare the results with quoted results at NIST pages.

Back to Cases

Navigation
Home Page
Special Offers
News

Products
Information

Order

Downloads

Information
Product Support
About us
Site Map
Resources
Testimonials
Customers
Link Request

  *

MtxVec© Janez Makovsek and Marjan Slatinek. All Rights Reserved. E-MAIL info@dewresearch.com. Delphi & C++ Builder are registered trademarks of Inprise Borland Corporation. All other brands and product names are trademarks or registered trademarks of their respective owners.
dogma