LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I need assistance entering an equation correctly into a formula node for curve-fitting.

I am developing a curve fitting routine to run with the data I collect from one of my instruments. My problem seems to be in using a formula node to correctly represent the equation I am using to fit my data.

My equation is y = a*x + b*exp(c*x)

However I feel there is a problem representing this equation correctly in a formula node. I can accurately represent the first term x (to which the curve-fitting vi assigns the parameter a), and the second term exp(x) (to which the vi assigns the parameter b).

My problem is in how to assign the parameter c to the x inside the argument of the exp term. If I create a third term in the formula node (which would get the desired para
meter c), and then have the exp term use this third term as an argument, the result of my curve fit suggests that Labview interprets the equation to be

y = a*x + b*exp(c*x) + c*x

Clearly this is not the equation I desire. Does anyone know if there is a way to accomplish what I want to represent. That is, I would like to have a curve fit parameter assigned to the argument of the exp term (but have no third term added).
0 Kudos
Message 1 of 30
(4,657 Views)
Consider z=c*x and then
y=a*x+b*exp(c*x)
=(a/c)*c*x+b*exp(c*x)
=(a/c)*z+b*exp(z)
and after doing the fitting for this one, go back to x=z/c.

Hope I understood the problem
0 Kudos
Message 2 of 30
(4,653 Views)
The logic you offer makes good sense, thanks. However there's still something I don't quite see (If it's evidence of my rusty math skills, I apologize).

It appears that the equation I should now enter into my formula node for curve fitting is: z+exp(z). That seems like it would work fine, just that I'd need to first use in my code the transformation z=c*x. Yet c is undetermined until I run the curve-fitting routine... I run into a similar problem, assuming the routine returns the parameter corresponding to the exp term (call it, d). Again, if c were known, it would be no problem determining a from d. However both a and c are unknown, and I need to know all the original parameters: a, b, c.

If you can point me in the right direction, that'd b
e great. Thanks!
0 Kudos
Message 3 of 30
(4,653 Views)
I mistakenly assume that c is known. Can you post your VI or send it to me (labviewer(AT)yahoo.com) ... maybe it will be easier to figure out a solution.
0 Kudos
Message 4 of 30
(4,654 Views)
These are my VI's as of when I first wrote about the difficulty I'm having. Probably the only one you need to be concerned with is the 2nd one ('Poling H Function Assembler...', 22K), the one that contains my equation to be fit. I've included the other 2 VI's that work in conjunction with it, in case you have any question of where the data comes from or goes to.

I wasn't able to include the data file , but I have no problem reading it in and performing the necessary transformations on it. It consist of 2 rows of 214 elements (raw X and Y values).

Hope this helps!
0 Kudos
Message 5 of 30
(4,654 Views)
I've included the data file, 30BLEND. If you run the 'Data Reader...' VI, be sure to specify the film thickness: 14.7.

Let me know if there's any other info I can provide you with.
0 Kudos
Message 6 of 30
(4,655 Views)
I saw your VIs and I think we have a little problem ... as far as I know, in order to use "General LS Linear Fit" you need y to have a linear relationship with the parameters you want to find out (and this is not your case). Therefore, you have to use "Nonlinear Lev-Mar Fit" - for details check LabVIEW Analysis Concepts - ! pay attention that you have to modify a formula node inside one of its subVIs ! ... you can find in LV folder one example for a function similar with yours.
Another way of resolving it is to convert the exponential best fit problem to a linear ls fit (is possible but I have no idea how to do it)

Hope this helps

0 Kudos
Message 7 of 30
(4,657 Views)
Yes, that seems to allow me to put together the type of equation I'm looking for, thanks. Do I need to modify the equation anywhere besides the rightmost true/false structure in the Nonlinear LevMar Fit.vi diagram? It seems to automatically update all the other subVI's when I do this, which is good. However I'm still not getting output that looks familiar, especially when I look at it on a graph. Is there something else I need to do? I'm including my VI's again, 1 of which has been updated.
0 Kudos
Message 8 of 30
(4,658 Views)
I do not have your modified "Target Fnc & Deriv Nonlin.VI"; Anyway, in case you are not using "numerical calculation" don't forget to fill in partial derivatives of f(x) with respect to the coefficients a.
And one more thing ... try to have a good "initial guess" for your coefficients - sometimes, they make the difference.

Good Luck
0 Kudos
Message 10 of 30
(4,659 Views)
Swordfish,
Using the fitting in LabVIEW is always somewhat tricky. Let me therefore see if I can help you on the right track here. I just looked at your code and I also read the other postings. Yes, this is a nonlinear problem indeed. However, I would suggest that you use the VI named Levenberg Marquardt.vi rather than Nonlinear Lev-Mar Fit.vi as you do (both are located in Mathematics/Curve Fitting). The latter is older and more primitive to use. With the new one you do not have to make any changes to subVI's since it uses the formula parser. The way to go NI!


Attached is an example I put togheter for you that shows how you can use the Levenberg Marquardt.vi with your equation. As you will see, I generated perfect Y data from an X array to s
ee if the resulting values for a, b, and c are correct. I hope this helps. Let us know if you need more help in this matter.

/Mikael Garcia
Message 9 of 30
(4,666 Views)