LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Piecewise linear function fitting

Solved!
Go to solution

I have data that approximates to the following function:

 

f(x) = A; x<E

f(x) = Bx + C; E<=x<F

f(x) = D; x>F

 

I am trying to use the non-linear fit function and having issues with a singular matrix error. I feel I have approximated my parameters pretty well, and the plot of the best fit curve seems to line up pretty well, but it seems as though it is not iterating through my E and F approximations and just using what I give it. Could someone take a look at my code and offer me some additional guidance? The points that I particularly need are the "A" value and when f(x)=0 from the second function. If there is an easier way to find these values I'm all ears.

 

Thanks

Download All
0 Kudos
Message 1 of 7
(4,154 Views)

You did not make the paramter estimates as default before saving, so all we have is an empty array.

What are your initial parameters?

0 Kudos
Message 2 of 7
(4,148 Views)

Ooops, sorry.

 

A = 1

B = -2

C = 10

D = 0.01

E = 3.8

F = 4.2

 

I also realized soon after submitting that E & F could be dependent on A, B, & C, so I am trying again with that in mind.

0 Kudos
Message 3 of 7
(4,145 Views)
Solution
Accepted by topic author bshover

Yes, you only need four parameters.

 

  1. Beginning level
  2. End level
  3. first x
  4. second x

(interpolate linearly between first and second x from first to second level).

 

See attached for a quick draft.

Download All
Message 4 of 7
(4,139 Views)

Thanks, that works much better. Given my data, it was going to be difficult to come up with a prediction for the slope and y-intercept, this works out much better as I know approximately what A should be, and where the x-intercept should be.

0 Kudos
Message 5 of 7
(4,133 Views)

Of course you could paramterize it in many different ways, e.g. intercept, slope, x1, x2, so modify as needed.

Just define the linear equation and, inside the model, coerce the x-values to lie between x1 and x2.

0 Kudos
Message 6 of 7
(4,128 Views)

@altenbach wrote:

Of course you could paramterize it in many different ways, e.g. intercept, slope, x1, x2, so modify as needed.

Just define the linear equation and, inside the model, coerce the x-values to lie between x1 and x2.


Here's what I had in mind.

 

See how simple the model gets! 😄

 

Message 7 of 7
(4,122 Views)