Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

slope of a line using national instruments linear fit

I am trying to calculate the slope of a line using 3 points.  We are converting a program written in VB6 to VB.net.  We were able to do this using the CWStat function in VB6.  In VB.net we are looking at using NationalInstruments.Analysis.Math.CurveFit.LinearFit.  I don't know what this function is needing from me.  We are trying to use this in a calibration screen in our program.  I did a slope of the line using 2 points but it is not very accurate.  I guess what I am looking for is the variables that the national instruments function need.  I am new to VB.NET so I really am green when it comes to all the programming terms.  Thanks for your help
0 Kudos
Message 1 of 6
(5,679 Views)
My first post my be a little hard to understand.  What I am looking for is a function that will return a slope of a line when I send it 3 (x,y) points.  What I am doing is trying to calibrate an ac voltage so that it can be scaled to display a different voltage.  I have a 0 to 10 volt signal that I am reading and I need to scale it to display 0 to 3000 volts.  I don't think it is very linear.  I can use 2 points and do the slope mathmatically but I am not getting a very accurate reading.  In VB6 I used the CWSTAT LineFit function and it would return the slope and offset of that line.  And when I mutliplied that by my 0 to 10 volt signal it was pretty accurate within a couple of volts.  I have tried to use the NationalInstruments.Analysis.Math.CurveFit.LinearFit but am having a problem getting my data in the right format.  I am not really sure that that function will actually do what I am wanting it to.  Like I said I have only been using VB.net for a couple of weeks and this is all new to me.  Any input would be greatly appreciated.
0 Kudos
Message 2 of 6
(5,658 Views)
Hi,

The LinearFit method firs the data set(x,y) to the linear model. This function is overloaded , meaning that, several methods with the same name can exist and are distinguishable by the parameters accepted and the return value delivered.

For the most basic implemented LinearFit Method use LinearFit(ByVal Double(), ByVal Double()) As Double(). This overloaded implementation of the LinearFit method will fit the data set (x, y) to the linear model using the Least Square method and default values for tolerance and weight. The function is expecting two double arrays, one for the x-data and one for the y-data. A double array of the filtered data will be returned. This information can be found in the Measurement Studio Help for CurveFit.LinearFit Method.

-Adri K
Adri Kruger
National Instruments
LabVIEW Product Marketing
0 Kudos
Message 3 of 6
(5,656 Views)
Ok I am getting a value back now but I don't know what it is.  I sent the function 2 points (1.7502,1005) and (2.6204,1501).  The value I am getting back is 1005.000000...8 and 1501.00000000007.  I don't know what to do what those numbers or what they even mean.  I would expect to get a number close to 575 back.  That would be my multplier that I use to multiply the lower number to so I can calculate the higher number.  In the VB6 I got back a value for the multiplier and an offset.  Any suggestions?
0 Kudos
Message 4 of 6
(5,647 Views)
Could you better explain your reasoning for using the Linear Fit function? If you are simply wanting to calculate the slope of the line using the two points you have indicated, you can use the following equation
 
m = (y2-y1) / (x2-x1)

Using the points you have defined above, his call can be made in VB.NET as follows:

Dim point1() As Double = {1.7502, 1005}
Dim point2() As Double = {2.624, 1001}
Dim slope As Double = (point2(1) - point1(1)) / (point2(0) - point1(0))


Adri K
Message Edited by Adri K. on 04-10-2009 10:51 AM
Adri Kruger
National Instruments
LabVIEW Product Marketing
0 Kudos
Message 5 of 6
(5,631 Views)
I am actually using 3 points.  The values for the x coordinate is read from a data acquision card and the value for the y coordinate is from user input.  I think I may have come up with a solution.  I used the CurveFit.PolyomialFit function.  It seems to return the value that I was looking for.  I went through my calibration procedure and when I was through the calculated values on the screen matched the digital meter.  So I think I may have it working.  Thank you so much for your help. 
0 Kudos
Message 6 of 6
(5,627 Views)