LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Linear fit

Hi

Can any one help me how slope of a linear curve is calculated in linear fit vi.

i calculated based on simple math formula but im not getting how linear fit vi is calculated.

i attached a vi, Please help in solving this problem.

 

Thanks and Regards

Ramesh

0 Kudos
Message 1 of 6
(3,330 Views)

Hi Ramesh,

 

when you think the linear interpolation is bad you should plot your data and the curve:

check.png

(black: your data, red: linear interpolation)

Why do you think a linear interpolation would give "good" results with your data?

 

See my attachment…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 6
(3,303 Views)

Fitting a function (like a straight line, a "linear fit") to a set of data involves creating a model that describes a relationship describing the data, some (statistical) assumptions about the distribution of errors in the measurements, and a fitting criterion for "what is the best fit?".

 

A common model, set of assumptions, and criterion is (model) there is a linear relationship between X and Y, (assumptions) X is "known" and Y is "measured", with some (often normally-distributed) variation about the "true" value, and (criterion) you want to find the value of Y (as a linear function of X) that minimizes the squared deviations between the measured Y values and the Y value predicted for that value of X.  This is usually called the "Method of Least Squares".

 

Given a set of (assumed precisely measured) X and (assumed measured with error) Y values, it is an easy calculus exercise to derive a formula to calculate the Y intercept and slope of the line that fits the data in the "Least-squares" sense.  This (should be) what the Linear Fit routine returns to you, particularly if you use the default "Least Squares" fitting method.

 

Bob Schor

Message 3 of 6
(3,291 Views)

Hi GerdW,

Thanks for your reply.

Why do you think a linear interpolation would give "good" results with your data?

The data which i linearly interpolated is not the best for my application. My intrest is to find the slope of the curve. the way i found slope in that vi is simple but its is not good for my application.

So im using linear fit vi, but i dint get how they calculated slope.

The modified vi you shared here is helpful.

 

Thanks & Regards 

Ramesh

 

0 Kudos
Message 4 of 6
(3,255 Views)

Hi Bos_Schor,

Thanks for your information that helps me in finding a solution.

I find slope based on some mathematical assumptions and formulae in math's , concepts under least square method. I got the exact results as same as linear fit vi values. find the attached vi for more details.

 

Thanks & Regards 

Ramesh

 

0 Kudos
Message 5 of 6
(3,254 Views)

@Rameshgowda wrote:

find the attached vi for more details.

 


  • You can remove the FOR loop. it is not needed and just clutters the diagram.
  • I would recommend to use a more sane connector pattern. If you think you need 20 connectors, something is wrong.
  • As has been said, your data is far from linear. Maybe you want to take the first derivative and graph the instantaneous slope at each x instead. What are you planning to do with the result?
  • What kind of experiment is this? Is there a mathematical model that describes the behavior?
0 Kudos
Message 6 of 6
(3,243 Views)