# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## How to extend x,y array with curve fitting

I have a plot curve.vi (image 1) and I want to extend the plot, similar to the red extensions in image 2.

Giving -x and +x as control inputs to limit the extension of the polynomial fitting array.

What is the best and fastest way to do it?

Message 1 of 9
(1,512 Views)

## Re: How to extend x,y array with curve fitting

Hi Mal,

do your polynomial fitting of your data to get the polynomial coefficients.

Then use those coefficients to calculate a new plot with extended x range!

What have you tried and where are you stuck?

(Do you use the Base or Professional version?)

I just created this in 3mins:

Hint: Learn to stay away from ExpressVIs!

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(1,503 Views)

## Re: How to extend x,y array with curve fitting

It's interesting, thanks!

Message 3 of 9
(1,464 Views)

## Re: How to extend x,y array with curve fitting

Often, extrapolating a regressed polynomial is a bad idea.

"If you weren't supposed to push it, it wouldn't be a button."
Message 4 of 9
(1,459 Views)

## Re: How to extend x,y array with curve fitting

I agree with Paul that blindly extrapolating is a bad idea. Especially with a 6th order polynomial!

How much do you know about the data? Is there a model (e.g. Truncated Gaussian or Lorentzian, Asymptotically linear on both sides, etc.?). To correctly extrapolate, you need a model that describes the entire f(x) from -inf to inf (or within the desired extrapolation limits), then do a nonlinear fit to the model and extrapolate using the best fit parameters and the model.

From the strange dropoff in the wings of the 6th order polynomial, we can tell that it is not a good model!

On a side note, you definitely don't need any dynamic data and express VIs. Here's the equivalent of your current VI. Arguably simpler!:

Message 5 of 9
(1,438 Views)

## Re: How to extend x,y array with curve fitting

Hi Altenbach, Paul,

Thanks I agree. How can I manage complex numbers solution? I think you mean probably I can change the x scale for example, how?

Message 6 of 9
(1,420 Views)

## Re: How to extend x,y array with curve fitting

@Mal123 wrote:

How can I manage complex numbers solution? I think you mean probably I can change the x scale for example, how?

What is there to "manage"? I am not even sure what that means. 😄

Here's a fit to a primitive Lorentzian shape (Definitely not the correct model, so this is just for illustration!). While the fit is not as good as the 6th order polynomial, it only uses 2 instead of 7 parameters. 😄

After fitting we take the best fit parameters (3.97, -0.18 in this case) and evaluate it for an arbitrary range of X values. (Yes, I would use more reasonable guesses as (1, 1), but it still finds it.

Once we know what the data represents and what the theory is, we can come up with a better model. Where does the data come from and what does it mean? What are the units?

Message 7 of 9
(1,406 Views)

## Re: How to extend x,y array with curve fitting

Hi,

@paul_cardinale wrote:

Often, extrapolating a regressed polynomial is a bad idea.

I strongly agree to this comment!

I just took a 6th order polynomial because it looked better than 2nd to 5th order (and for simplicity of example…) 🙂

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 9
(1,397 Views)
Solution
Accepted by topic author Mal123

## Re: How to extend x,y array with curve fitting

If we allow an x shift (i.e. 3 parameters), the fits already gets better:

Still, not perfect, of course because we need a better model!

Message 9 of 9
(1,394 Views)