Nonlinear curve fit

Hi everybody,
I am trying to fit a custom nonlinear curve to my data. I want to fit a curve to the data twice. After the first fit, I want to use the coefficient a (6.57962) in my second curve fit as my coefficient b. When I try to use this and create a custom equation by string concetanete, everything seems fine but I do not get what I expect to get. To double check I used curve fitting express VI and I added 6.57962 as a coefficient in my equation and at the end a turns to be 6.752. However, this does not happen in my second curve fit. Does anybody have any idea what might be wrong? I cannot find my mistake, could you please help me?
Thank you very much
Attachments:
Read.vi ‏129 KB
read.png ‏66 KB

The errors you get provide some clues, although they are not very explicit.
The -23001:  Syntax error of parser  is usually a sign that your string describing the function is ill-formed or that there is a parameter mismatch. You have both.
The string array constant feeding into the second Lev-Mar VI has two elements, the second one being an empty string.  Even though the string is empty, the parser expects two elements in the Initial Parameters array. But since your equation has only one parameter (a), the proper solution is to remove the blank element from the constant array.
The other problem is that the first Initial Parameters array is empty.  Maybe you always enter two values but I did not know what to put in. 
The second fit is somewhat sensitive to the initial Parameter value. Negative values do not work. 1 returns 6.753... 2 through 6 and 8 (integer values only) return 6.246... 7 returns the same result as 1. Values 10 and above return the value entere with error -20041 (singular matrix) appearing at >=12.
The initial b parameter in the first fit does not matter over a fairly wide range.
I also noticed that you seem to have a severe allergy to straight wires. Wires running all over the diagram and particularly behind other objects makes it very hard to read your code. Dataflow along the wires should generally be from left to right as much as possible. The code works the same regardless of the number of bends in the wires but straighter wires are much easier on the programmer.
Lynn

Similar Messages

  • Nonlinear Curve Fit LM Formula String in Labview 8

    hi, guys. I write a vi which use Nonlinear Curve Fit LM Formula String. When I run it ,the program says "Syntax error of parser." and I don't know what's wrong with it, so help me,Please. By the way ,you can fill the arrays as you wish.
    帖子被trinight在02-11-2006 07:51 PM时编辑过了
    Attachments:
    curve fitting.vi ‏16 KB

    You MUST wire initial estimates for the parameters. Attached modification works just fine.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    curveFittingMOD.vi ‏17 KB

  • How to use the parameter "data" in the vi of Nonlinear Curve Fit

    I used "Nonlinear Curve Fit" to do state estimation. If I make the number of unknows a constant number, it is fine to code the fitting model for f(x,a). But if I want to code the number of unknows as a variable, how can I do this?
    Maybe "data" should be used here. But I just could not find any examples talking about how to use "data" here.
    Thanks.

    Hey hilary,
        Have you looked at the LabVIEW help for the Nonlinear Curve Fit VI?  Which version of LabVIEW are you using?  In mine, the VI is polymorphic, and you can declare the formula to be a formula string.  Then it provides pins to enter the input parameters programmatically.  Perhaps you could post a screenshot of how you are currently using the VI, and we could help more.
    Brian B
    Field Sales Engineer
    Tennessee/Southern Kentucky
    National Instruments

  • Gaussian Peak Fit and Nonlinear Curve Fit on small data differ from Origin Peak fit

    Hi all,
    I am developing a program in which I have to fit Gaussian curve on only 4 or 5 data points. When I am using Gaussian Peak Fit or Nonlinear Curve fit, it linearly connects all the points while other fitting software like Origin is fitting Gaussian curve on the same set of data I have attached two images One is from Labview with Gaussian Peak Fit and NonLinear Fit and other is from Origin.
    Data is
    X                       Y
    799.09857        257
    912.25256        641
    1026.00366     1516
    1137.92871     1118
    1253.43713     329
    Labview user
    Solved!
    Go to Solution.
    Attachments:
    Origin_Fit.PNG ‏21 KB
    Labview_fit.PNG ‏15 KB

    That looks like a plot of the input data.
    When I run it with your data I get a Gaussian curve which looks much like your Origin plot.
    The Plot 2 curve is from 128 points equally spaced along X and Y calculated from the Gaussian formula in the LV help using the output parameters from the fit.  Plot 1 is the Best Gaussian Fit output from the fit VI.  It only has five points.
    I used default values for everything except X and Y.
    Lynn

  • Constrained nonlinear curve fit can properly handle the function like ln(1+b(x-xc)/a) ?

    Hi all,
    I met some problems about using constrained nonlinear curve fitting vi. It seems to me that this vi can't properly deal with the function like ln(1+b(x-xc)/a), a,b, and xc are the parameters, and b is in the range of 0 and -1. The reason I said that is as I used the other nonlinear fitting function in the other software, like Originlab, the fitting function can work properly.
    The error message from LV occurs as 1+b(x-xc)/a is less than zero. 
    However, due to a,b are both adjustable parameters, how could this situation happen ?
    Now I attach the vi files. The attachment includes main vi, mathmatical formula, and an input XY txt file.
    I appreciate any help or suggestion from you!!
    Here is the error message
    Joy
    Solved!
    Go to Solution.
    Attachments:
    LN-fitting.vi ‏21 KB
    LN-fittingmodel.vi ‏18 KB
    Book2.txt ‏1 KB

    Thanks for reply. whitenoiz 
    Actually I have more than 100 XY data set to test my vi. Some of the data set can be fit flawlessly. And the best fit parameters obtained from my vi are exactly the same as those from other analytical software, like OriginLab. In this case, I know my vi is valid. And in this scenario, I also found 1+b(x-xc)/a is always larger than zero with the best fit parameters (a and b). However, for certain XY data set, the error message will pop up if I use LV built-in vi, but I still can obtain the best fit parameters with OriginLab. And then I realized that error message always pops up as 1+b(x-xc)/a is less than zero, which it means to me that as LV built-in vi handles this type mathematical function, this built-in vi will encounter some difficulties. 
    I will step through my code, and also focus on the Matrix Left DivisionMV.vi, try yo find where the problem is.
    Best regards,
    Joy

  • Constrained Nonlinear Curve Fit VI: Termination Revisited (LabVIEW 8.5)

    Hello:
    In the Constrained Nonlinear Curve Fit VI, the Help for the VI states that if the number of iterations exceeds max iterations specified in the termination control, the fitting
    process terminates. Would this not indicate that if the above condition is met, the number of iterations recorded (an output of this VI) should be equal to the max iterations specified (since the VI is exits at this point).  I believe I have seen situations where this condition is met, yet the number of iterations recorded is greater than the max iterations I have specified in the termination control.  Has anyone else seen this?
    Thanks,
    Don

    Don,
    Just wanted to clarify the termination criteria for the nonlinear curve fitting routines.  There are two criteria used to terminate the fitting process:
    "max iteration" and "tolerance".  The main while loop terminates when either of these conditions is met, so:
    IF( (current_iteration > max_iteration) OR (current_tolerance <= tolerance) ) THEN (terminate loop)
    "current iteration" is just the current loop counter(starts at 1 for the first iteration).  This term is mainly a guard against having the fitting process run too long.
    tolerance is computed as the relative change between the current and previous weighted least squares values.
    Let wls = SUM_OVER_ALL_X( weight(x)*(f(x,a)-data(x))^2 )
    current_tolerance = ABS(current_wls - previous_wls)/(ABS(current_wls) + machine_epsilon)
    where ABS indicates absolute value.  Adding machine_epsilon to the denominator is just a guard against division by zero.
    For the bound nonlinear curve fit VIs, if the "method" input is chosen to be LAR or bi-square, then wls is defined as:
    wls = SUM_OVER_ALL_X( weight(x)*reweight(x)*(f(x,a)-data(x))^2 )
    where reweight(x) is a term reducing the weight of high-leverage data points.
    For both the constrained and unconstrained fitting routines, if the weight input is unwired then all points are considered to have a weight of 1.
    Christian has nicely covered the difference between the number of iterations and the number of function calls.  If your
    When the fitting process terminates the best result obtained so far is returned.  As you noted, this may be a good result, although the algorithm may not have completely converged yet.
    -Jim

  • Nonlinear Curve Fit and using static data

    I am trying to fit data to a 2D function using the Nonlinear Curve Fit VI in Labview 8.2.1, but I would like to also include 2 parameters that I don't want to be optimized.  I cannot directly use constants since every time I run the fitting I need to change the 2 parameter values.  I tried to modify the example by Altenbach according to my own application in the link below. 
    http://forums.ni.com/ni/board/message?board.id=170&message.id=230831
    I think the problem is that I don't completely understand how to use the static VI reference with the Nonlinear Curve Fit VI?  It looks like there is a static data control that I could use to add additional parameters, but I am not sure?  I can get Altenbach's code to work if I change the function to something different, and even if I change the number of inital fitted parameters.  I just can't figure out how I can add parameters using a control that will not be optimized.  I can attach an example, but it is very similar to Altenbach's code except the function is different, and I am trying to add additional parameters that are not optimized.  Thanks for any help.
    Kevin Baker 

    Thanks Trey.  I am sorry I didn't make it clear what I was talking about before.  I am attaching an example that will hopefully clarify what I would like to do.  When I try to pass the static reference to the Nonlinear Fit VI it says gives me a broken wire and says "function conflict".  I am assuming the problem is that I inserted another control to the VI when I wasn't supposed to.  I just don't know of any other way to pass data into the VI, and still have the Nonlinear Fit VI still work?  What is the "data" control in the Nonlinear Fit VI used for anyway?  It seems that that it was want I need, but I don't know how to use it?  Thanks again for any help.
    Attachments:
    Fit equation.vi ‏15 KB
    general lorentzian.vi ‏26 KB

  • For "Nonlinear Curve Fit.vi", what does -20068 mean and how can I avoid it?

    Hey guys,
    I am trying to fit an oval in a set of 2D data points, which represents a partial oval.
    So I am trying to see if "Nonlinear curve fit.vi" would work in the situation.
    However, sometimes that math VI would give me an error -20068 and would return incorrect fitting parameter.
    I can't figure out what condition would return that error so can you tell me
    what the cause is and how I can avoid that error?
    You can run the attached LabVIEW 2013 VI and see the error.
    Attachments:
    ellipse fit data.zip ‏41 KB

    jcyth wrote:
    The model is a result of solving the ellipse equation for y, 
    (x^2)/(a^2) + (y^2)/(b^2) = 1
    So I don't really see a simple way to make the negative values less likely...
    but maybe I can use "Constrained Nonlinear Curve Fit" where I can bound the parameters then?
    This is slowly drifting away from a LabVIEW problem but any help is appreciated! 
    The solution is to re-parameterize the problem and solve for something much less pathological
    You can directly fit for the above formula by providing x&y for all points to the model and optimize the four ellipse parameters until you get an array of all ones.
    I quicky coded this in the attached example and it seem to be quite stable, even with lots of noise.
    See if this works for you.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Ellipse FittingMODCA.zip ‏40 KB
    FitEllipse.png ‏26 KB

  • Nonlinear Curve Fit Error

    I am trying to get a multi-dimensional fit working by using a nonlinear curve fit VI and everytime I run it I get an error saying that my samples need to be greater than 0. The specific error message is: "Error: Analysis samples need to be > 0." Does anyone know what is wrong? I have tried to reinitialize my input parameter array to zero, recompile the VI, etc. and still get the same error regardless.
    I have attach all my VI's.
    Thanks,
    Ynessa 
    Attachments:
    Multidimensional Fit.zip ‏65 KB

    ytran wrote:
    I am farely new to labview and have not figure out the best way, so that my diagrams stay smaller since my width and height are farely large. What do you mean eliminate the local variables in the loops of the model? 
    In the model, you have a hidden indicator called pixel size, which you write once outside the loop and then continuously read over and over again with every iteration of the loops via local variables. SInce the value does not change during the execution of the loops, reading the same indicator over and over is just a waste of efforts. Why involve the UI if the valie is right there in the wire?? The correct way would be to delete that indicator and the local variables and simply connect all by wires.
    Did you understand my other comments?
    ytran wrote:
    The typical values for the controls are as follow:
    Pixel Size (um) = 5.2
    x0 (mm) = 640
    y0 (mm) = 512
    Focal Length (mm) = 1000
    Wavelength (mm) = 561
    Beam Diameter = 1
    Amplitude = 100
    Background Amplitude = 10
    Are all of those fitting parameters or are some of them constant and known?
    LabVIEW Champion . Do more with less code and in less time .

  • Nonlinear Curve Fit VI keeps all initial parameters

    My question is about fitting a curve with nonlinear curve fit VI. The fitting function has the formula like
    A/((x/I)^p-C)+B, where fitting parameters are {A, B, C, p, I) and variable is x. I tried to use both Nonlinear Curve Fit VI and Constrained Nonlinear Curve Fit VI, but neither gives me fitting parameters other than what I input as the initial parameters. As an example I am attaching the data set file where the fist column is x and second column is y. The initial fit parameter set is {2,0,1,2,90}. It would be appreciated if someone could point out how I use either these fitting function to get the best fit.
    Attachments:
    60QR.zip ‏1 KB

    Actually my LV code is quite simple and has nearly nothing more than the nonlinear curve fit vi itself. Anyhow I am attached my code here so that you could at least run and see what my question is about. The caller VI is "Curve Fitting.vi". The subVI inside it that calls the curve fitting function has two flavors inside. What is enabled uses the contrained nonlinear curve fit vi while the other one that is currently disabled, calls the function of nonlinear curve fit vi.
    Thanks.
    Attachments:
    Curve Fitting with a Nonlinear Model.vi ‏29 KB
    Curve Fitting.vi ‏17 KB

  • Nonlinear curve fit help needed

    I am in need of some help trying to fit a set of data that requires the use of nonlinear curve fitting.  I have attached a txt file containing the data that needs to be fitted.  The first row contains the x-axis values while the second row contains the y-axis values.  The model for this set of data can be described by a single parameter, A, for the first five data points.  The remainder of the data points can be described by the model A+A1*exp((0.4-x)/A2), where A, A1, and A2 are all parameter.  As you can see the two models share the parameter A.
    I have determined some initial values for each of the parameters: A=176.32, A1=2133.4133, and A2=1.4936.
    I have spent the last couple of days trying to figure out how to use the Lev-Mar nonlinear curve fit vi but have had little success.  I have been doing LabVIEW programing for many years now and I have never felt as lost as I do now trying to understand how the Lev-Mar nonlinear curve fit vi works.  Any help you can provide with my data fitting would be greatly appreciated.
    Thanks.
    -Alonzo
    Solved!
    Go to Solution.
    Attachments:
    Data.txt ‏1 KB

    I think the problem is that the first 5 points are not part of the data sent to Lev-Mar.  Because of this the fitting process fits the remaining data very well, but the constant term is able to freely move.  I modified the model function to output A for the first 5 terms, and the complete function for the rest.  The offset found is now more reasonable.
    Also, your quote your model to be A+A1*exp((0.4-x)/A2), but what is implemented in the model VI seems to be A+A1*exp((x-0.4)/A2).
    -Jim
    Attachments:
    ExponentialFunction.vi ‏19 KB
    FitExponentialExample.vi ‏24 KB

  • How can I modify the NonLinear curve fit in 7.1 to a new formula?

    My problem is something like this.
    I am a beginner in LabVIEW and I have been trying to put together a piece of program that would acquire, analyze and display data from dynamic light scattering. I used a Formula Node to create a autocorrelation function which works a lot faster that the function that is on the functions palette and I have my final results in array and graph forms. I tried to look at the examples provided in the software package for some nonlinear fitting and I found the NonLinear Lev-Mar Fit.vi which would do something close to what we needed, but not enough. The autocorrelation data looks as a simple exponential decay, but the fitting procedure needs an extra term in the fitting equation to account for any undesired noise in the solution of interest. That term includes an Exponential Integral which LabVIEW had in its special function section. The problem that I have is to Modify the Lev-Mar fitting vi to account for the change. My formula looks something like:
    f = (B*exp(-A*x) + (1 - B )* ExpIntegr (g*x))^2
    where A and B are our fitting coefficients and the information of interest is included in A.
    Thank you very much for your time.

    What is g? A constant? Another fitting parameter?
    It is hard work to adapt the old lev-mar fit to a new model. Things are much improved in LabVIEW 8.0+, where the model VI is called via reference and tons of other improvements were implemented.
    I made similar improvements in 7.1 and you can e.g. try to modify one of my many such postings. I posted one involving exponential integrals a long time ago.
    (Download the example EI_Fit.llb)
    To adapt, just change the model and adjust the number of parameters if needed.
    For details, check the original thread. Let me know if you have any questions.
    LabVIEW Champion . Do more with less code and in less time .

  • Curve Fit of ODE, should I use Lev-Mar or Constrained Nonlinear Optimization?

    I wanna do a curve fitting of differential equations, following is the equations:
    dx/dt = u*x-a*x
    ds/dt = b*u*x+c*x
    dp/dt = d*u*x+e*x+f*p
    and u = um*s/(km+s+s^2/ki)
    I've tried "nonlinear curve fit( Lev-Mar)", but I met difficulties when writing the f(x,a) of Lev-Mar.
    Then I tried "Constrained Nonlinear Optimization", I found that the example "Estimate Nonlinear Spring Constant.vi"
    in the "labview\examples\math\curvefit.llb" was similar to the fitting I tried to do, but there was only one parameter
    need to estimate in this example,but what I need is to estimate 3 parameters.
    However,I modified the example to my equations, it failed again.
    How can I achieve this? is it possible to do this fit only using Labview VIs or need Matlab Script Node?
    Any help will be appreciated.

    I forgot to mention that in the equations above,  a,b,c,d,e,f is constant,
    and the data of x,s,p corresponding with the data of time is already known,
    and which parameters I wanna identify is um,km,and ki
    帖子被myafu在12-22-2006 01:33 AM时编辑过了

  • Curve Fitting

    Hi 
    I have a set of measurement data that i wish to fit to a complex curve.
    After the fitting i need to find the constants from the curve and use them for further calculations.
    equation for my curve is 
    x= -a* integral(p^n dt) + c.,
    where x,p are known data sets at time t. 'a' and 'n' and 'c' are constants. after the fitting i have to find best values for a and n.
    somebody please explain how i can accomplish this.
    Waiting For the inner calling

    Inorder to use the  Levenberg-Marquart method, it is neccessary to specify the formulae string. but how can i specify a formula containing integral function as a labview string.
    Warm regards
    Deepu Jacob
    DFGray wrote:
    You have two main options:
    Convert the integral to an actual equation, then use a non-linear fitting routine, such as the Levenberg-Marquart, to do your fit. You will need approximate values for your parameters before you start.
    Use one of LabVIEW's numeric integrators to do your integral, and use a non-linear fitting routine to find the parameters. This will be slower.
    Before you go any further, I would strongly recommend you read the chapters in Numerical Recipes, 10 and 15, about fitting data to parameters. Nonlinear curve fitting can be very finicky, so you need to know what you are doing. LabVIEW has all the algorithms (if you have a student, full, or pro version), so you won't have to code much more than your actual function.
    Good luck! Let us know if you run into problems.
    Waiting For the inner calling

  • Why doesn't my non-linear curve fit finish?

    I am working with an experiment that gives me X- and Y- data that I need to fit to a theoretical model (somewhat involved). I use to do this in matlab using the "lsqcurvefit", which works fine,
    but for varous reasons I need to do this in LabView instead.
    So, first thing I did was to make a vi which is my theoretical model. I throw in my X-data and get the Y data out of it.
    This vi works fine of it's own, but now I want to do my fitting by calling the model-vi from the Nonlinear curve fit.vi. I enter the same initial parameters, termination conditions, upper- and lower boundaries as in the matlab code, but no matter what, after some 100 function calls, the curve fit interrupts and tells me:
    "Error -20041 occurred at NI_Gmath.lvlib:Nonlinear Curve Fit LM.vi
    Possible reason(s):
    Analysis:  The system of equations cannot be solved because the input matrix is singular."
    I have tried to locate the problem at varoious levels but I get confused when I start to look into the nonlinear curve fit vi, I just lose myself in tons of block-diagrams.. Can anyone see what my problem is? I'd sure appreciate it! I added the necessary files. Main vi: langevin fit. vi, then open the data.txt.
    Thanks
    Attachments:
    langevin fit.zip ‏94 KB

    Your model function does not produce anything resembling your data. As a first step, graph the data using your initial guesses, here's how it would look.
    Here' the data and your initial guess on the same graph. You need to find initial guesses so the output resembles your data.
    My best guess is that your model is faulty. It is very hard to debug, because it is a mess: deeply stacked sequence structures and unneeded local variables. Also the model parameter constants should be provided via the "data variant" input instead of a global variable. You have a weird mix of datatypes. Why is half of the stuff EXT instead of DBL for no reason?
    I would also highly advise NOT to color your own VIs light yellow. Don't make them look like system tools!
    I am busy today, but maybe I can have a stab at it tonight. Good luck!
    Message Edited by altenbach on 07-06-2009 08:59 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    langevinFit.png ‏21 KB

Maybe you are looking for

  • Select Query for smart form-invoice

    Hi Folks, I have to fetch the following fields as per the requirement for desiging a invoice smartform.I had copied lb_bill_invoice smartform into z format. Can anyone here please give me the select query for the same. fields to fetched are as follow

  • Using loop in dbms_advisor Package

    Dears,, I used dbms_advisor package as following below dbms_advisor.create_object task_name => name, object_type => 'TABLE', attr1 => 'HR', attr2 => 'Employees', attr3 => NULL, attr4 => NULL, attr5 => NULL, object_id => obj_id what i need is to use l

  • Accessibility options not working in Captivate 7

    I need help. I can't get my project to in captivate 7 to be accessible. I've tried testing on JAWs and for some odd reason it seems like the enable accessbility is not working cause everything is messed up when I test on JAWs. Is their anybody that w

  • Module pool:- i send mail to sap

    i send mail to sapin this mail i send vbeln(sales docu. no). when user open dis mail and click on vbeln-related alv report open---plz send how to cleate link when send this type mail

  • Report by year quarter or month

    We have requirement where we may have to show some reports by either year,quarter or month.How this is supported in OBIEE answers ?