LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

curve fit

Solved!
Go to solution

Hi! I want to ask how I can fit a curve and see this in the graph for the obtained 2d array.

I can obtain a 2d array (x-y) as a result of loop iteration clicking "Next Step" button for 14 times. After that, I want to fit a curve for this 2d array as a function of y=f(x).

 

Also, I want to see the formula, and also function coefficients for this curve.

 

I have tried a curve fitting as can be seen from the attached picture. However, it always failed. I can not obtain purely x-y curve (y=f(x)). Also, I have attached the sample VI. Could anyone help me ? I'm looking forward to hearing from you.

Download All
0 Kudos
Message 1 of 50
(4,277 Views)

I spent some time cleaning up your diagram so I could see what was going on.  The style guides suggest keeping the diagram to the size of one screen.

 

I think you need to transpose the 2-D array going to the fit graph.  When I do that, it appears that the fit is quite good.

 

Lynn

0 Kudos
Message 2 of 50
(4,242 Views)

What is the purpose of the second while loop? Since there are no controls, nothing will ever change so it does the same calculation over and over for no reason.

0 Kudos
Message 3 of 50
(4,223 Views)

Hi, Johnsold,

Thank you very much for your reply and solution. It looks like better than previous one. However, there are some wrongs.

The x value of 2d array is r/R value which is denoted in the graph. The y values of the 2d array are u(r) values. But, in the graph, r/R values change between 0 and 13. I think these values are iteration numbers. 0-1-2-3-4-5...13. So the r/R values must be x values 0;   0.165;   0.278;  0.391..........; 1.

But, in the graph these values are in y-axis. These must be in x-axis. In the y-axis, the values must be nearly 2 for all r/R values.

Could you please help me for this respect. Thanks again! 

0 Kudos
Message 4 of 50
(4,205 Views)

Hi Johnsold!

I did not attach the file in the previous message. Now, I attached it. You can see the locations of r/R and u(r) on the graph.

0 Kudos
Message 5 of 50
(4,202 Views)

I attached the second while loop to use its stop button. I defined its stop button as a "Curve Fitting" button as can be seen from the front panel.

My question is how I can obtain a graph for 2d array.

The x-axis will be the first column of the 2d array. The y-axis will be the second column of the 2d array.

And after obtainig the graph, the curve will be fit to the data on the graph and the equation for this curve will be found. How can I achieve this? I'm trying mant things however, I have not found the solution yet. I need someone's help. Please help me to achieve the correct VI. The original VI is attached to the mail.Thanks...

0 Kudos
Message 6 of 50
(4,199 Views)

 

Could you attach a typical data file? Thanks!

 

Even better, create an indicator on the 2D array leading to the second loop. Run the VI and start fitting so the indicator contains 2D data. Now make the new indicator a constant with typical data (right-click terminal...change to constant). Now save and attach the VI. 

 

 


@mechen wrote:

I attached the second while loop to use its stop button. I defined its stop button as a "Curve Fitting" button as can be seen from the front panel.


 

Why not make it a state machine with a single loop? Your data is already in shift registers, so it would be available in the main loop. All you need is another state. The way you program it, you cannot easily go back to reading new data without additional code. Your fitting loop still needs a small wait or an event structure. Fitting needs to be done only of one of the inputs changes and not millions of times per second. You also don't need to wire all inputs, only the ones you want different from the defaults.

Why do you have two instances of the same 2D array diagram constant. This makes the code unmaintainable, because identical changes would need to be done in two different places if you need to modify things in the future.

 

 


mechen wrote:

My question is how I can obtain a graph for 2d array.

The x-axis will be the first column of the 2d array. The y-axis will be the second column of the 2d array.


If x is not spaced equally, you need an xy graph. Simply extract the two columns using "index array", then bundle them into an xy graph. Check the shipping examples.

 

 

0 Kudos
Message 7 of 50
(4,187 Views)

Hi altenbach,

I have tried things that you suggest. However, it does not work and the graph looks like the picture that I attached. If it is possible, could you please add another state in case structure for a state machine. I attached a picture of the graph.

In the graph, I want the value of x-axis 0; 0.165; 0.287; 0.391.........; 1 which are the values of the first column of the 2d array and I want the value of y-axis as the values of the second coulmn of the 2d array which are the values obtained as a result of 14 loop executation.

However, in the x-axis of the graph the values are varying between 0 and 13 which are the number of loop.

Could you please add the state machine for obtaining the x-y graph curve and the formula of this curve? Thanks again.

Download All
0 Kudos
Message 8 of 50
(4,167 Views)

Hi altenbach and johnsold,

I have tried to fit a 2d array in the first loop. And as you said, I have indexed the array firstly and then plot the x-y graph. However, The x-axis of the curve is again the number of loop iteration from 0 to 13. However, the first column of the 2d array appears in the indicator as a probe locations of 1; 0.977; 0.955 ......0.284......0 etc. So, these values are not accepted as x-values by the specified program. But I want these values in the first column of the 2d array as x-values in the x-y graph and the second column of the 2d array as y-values. How can I achieve this? Could someone help to me? I have attached the picture that show the wrong x-y grpah according to identified 2d array elements and attached the last VI.

 

Please help me!!!! Thanks again to everbody who helps or does not help me!!!!

Download All
0 Kudos
Message 9 of 50
(4,161 Views)

Hi altenbach and johnsold,

I have tried to fit a 2d array in the first loop. And as you said, I have indexed the array firstly and then plot the x-y graph. However, The x-axis of the curve is again the number of loop iteration from 0 to 13. However, the first column of the 2d array appears in the indicator as a probe locations of 1; 0.977; 0.955 ......0.284......0 etc. So, these values are not accepted as x-values by the specified program. But I want these values in the first column of the 2d array as x-values in the x-y graph and the second column of the 2d array as y-values. How can I achieve this? Could someone help to me? I have attached the picture that show the wrong x-y grpah according to identified 2d array elements and attached the last VI.

 

Please help me!!!! Thanks again to everbody who helps or does not help me!!!!

Download All
0 Kudos
Message 10 of 50
(4,161 Views)