LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to extend x,y array with curve fitting

Solved!
Go to solution

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?

 


 

Download All
0 Kudos
Message 1 of 9
(2,156 Views)

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
0 Kudos
Message 2 of 9
(2,147 Views)

It's interesting, thanks!

0 Kudos
Message 3 of 9
(2,108 Views)

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
(2,103 Views)

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!:

 

altenbach_0-1669051706189.png

 

0 Kudos
Message 5 of 9
(2,082 Views)

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?

0 Kudos
Message 6 of 9
(2,064 Views)

@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.

 

altenbach_1-1669055924109.png

 

 

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?

0 Kudos
Message 7 of 9
(2,050 Views)

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
0 Kudos
Message 8 of 9
(2,041 Views)
Solution
Accepted by topic author Mal123

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!

 

altenbach_1-1669057612899.png

 

altenbach_0-1669057775897.png

 

 

 

0 Kudos
Message 9 of 9
(2,038 Views)