# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Linear fit through the zero point [0,0]

I need to calculate the slope of a set of data and i want the slope to be forced to go through the zero point [0,0].

I tried the Linear fit.vi but i cant find a way to get the slope value through the zero point.

For example you can do it in excel by setting the third argument to false or 0 like in the example below.

LINEST(DataAccending!C8:C207;DataAccending!B8:B207;0)

How do i solve this in labview?

Thx.

Message 1 of 6
(288 Views)
Solution
Accepted by topic author tokar

## Rif.: Linear fit through the zero point [0,0]

You may use the General Polynomial Fit vi with polynomial order = 1 and constraining the 0 order coefficient to 0 in the Coefficient Constraint input.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 2 of 6
(281 Views)

## Re: Linear fit through the zero point [0,0]

If I had this problem, I'd start with Pen and Paper, write down the equations for least-squares to fit, then program the (very simple) algebraic calculation to get the slope of the best-fit line (the equation, of course, is y = mx).  Bound to beat a "general least-squares" routine, plus the fun of "doing the math".

@toker:  Were you able to get an answer by following the previous suggestions?

Bob Schor

Message 3 of 6
(219 Views)

## Rif.: Linear fit through the zero point [0,0]

It works!

Thx alot!

I also find another solution, see below.

Message 4 of 6
(211 Views)

## Rif.: Linear fit through the zero point [0,0]

You definitely don't need a formula node anywhere!

(se also my slide #13 from a few years ago)

Message 5 of 6
(206 Views)

## Rif.: Linear fit through the zero point [0,0]

Here's are two alternatives to do a linear fit with the offset forced to [0,0]

Message 6 of 6
(197 Views)