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时编辑过了

Similar Messages

  • Lev-Mar template missing

    I am trying to fit A*sin(w*t+phi) to some noisy data (amplitude, frequency, and phase are all to be detrmined from the matched sine). When I looked at the Lev-Mar fitting VIs I could not locate the template for the LM model function and gradient VI template mentioned in the Help file. labview\vi.lib\gmath\opti.llb\numerical is empty. (Help says this template should be there). The figure in the help file shows a cluster called Output Control as an input to the VI, but does not specify the elements of the control. I also could not find a way to put the formula into the String Formula version. Is there a listing of the available functions and syntax? The help did not seem to lead me to it.
    LV8.0.1 on Mac OS X
    Maybe it is just too late on Friday afternoon.
    Lynn

    Sarah, Christian,
    I had looked at that link and several others. I was hoping to find some reference where someone had made some practical suggestions reagrding optimizing the initial guesses, or at least some clues as to how to go about it.
    My data has a frequency range of about 2.5:1 so I was hoping I could just set the initial guess at the middle of the range. In my testing an initial guess 20% above or below the actual frequency resultis in erroneous values about 80-90% of runs with noise at 10% of signal amplitude which is better than the real data. With initial amplitude and phase equal to the data parameters and initial frequency guess at 1.2 times the actual I recorded two runs with the fit frequency at 99.9%. Eight others produced: 160%, 180%, 210%, 160%, 160%, 130%, 60%, and 160%. With the initial frequency at 80%, the results were somewhat worse.
    My suspicion is that because the partial derivatives of the model equation are also sines and cosines, the algorithm tends to find some kind of local minimum and converges to that even though it is a really poor fit.
    Here is my modified Lev-mar VI and the simple sine model VI (LV8). The default values are fairly typical of the data sets we will be getting.
    Thanks for the help.
    Lynn
    Attachments:
    Nonlinear Fit Lev-Mar.Berry.vi ‏41 KB
    simple sine model.vi ‏21 KB

  • Lorentz fit of a curve with Lev-Mar

    Hello everybody! I am trying to set of data to a Lorentz curve to calculate a Q value (resonance.) I found a program on a thread from this forum that appears to work with the sample data set from the thread. However, when I try to run the program using my data set with known fitted coefficients as the initial guesses, we get an error in the Lev-Mar sub-VI -- something like “the input matrix is singular”. There’s a screenshot of my data in in the attached zip folder, as well as the text file containing my data.
    My data curves down (reaching a minimum) instead of up, as in the sample data set, but it seems like that should be accounted for by the different initial guesses. I am thinking that something else is going on; hopefully it is something simple that I am just missing. Any help y'all can provide would be greatly appreciated!
    Thank you!
    Attachments:
    Lorentz Fit.zip ‏1992 KB

    Hello Lynn,
    Yes, there are quite a few potential peaks in that data set. The peak you identified was the one that we are trying to fit (The peak should be trimmed by the cursors.) We used origin to fit that same peak in order to get the initial guesses for the coefficients in the screenshot. When it runs, we get the error message: "Error -20041 occured at NI_Gmath.lvlib: Nonlinear Curve Fit LM.vi:2 Possible reason(s): Analysis: The system of equations cannot be solved because the input matrix is singular." 
    Thanks!
    -Garrison

  • 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

  • I'm showing a video on a wall that's 3646 x 768 px. What project dimensions should I use to best fit the space?

    I'm showing a video on a wall that's 3646 x 768 px. What project dimensions should I use to best fit the space?

    Try this : http://library.creativecow.net/payton_t/FCPX_Custom-Resolution-Timelines/1
    Switchie2

  • 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

  • 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

  • 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

  • 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

  • Curve fitting during daq

    I would like to perform curve fitting during my data acquisition such that, as more data is collected, the curve will be more accurate. So the fit curve should be anchored at some point in time, and then update on my chart as data is collected. I would like to plot this on my chart while I'm performing the daq as a means to filter out some "noisy" incoming data, and to try to forecast an event (reach a specified voltage level).
    Will this require a graph instead of a chart?
    Can anyone suggest any examples of this "real-time" curve fitting?
    Thanks.

    Re: graph or chart,
    you pick em based on what you prefer.
    I have done things like this to to some predictions based on history. You will be best served if you decide what kind function you will be fit. Simpler stuff can be handled explicitly. The more advanced would profit by using the modal analysis tools.
    You have a number of other challenges here.
    1) Filtering induces a phase shift. THis can be handled using a "zero-phase" shift technique (I found it on this site some yeras ago).
    2) Edge effect. When you zero-phase shift, you loose resolution at the begining and end. Problem is that the "most recent end" is the end you are most interested in because you are trying to do predictions.
    What do you expect your data to look like?
    How fast is it coming in
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Curve fitting gives input, at the output

    Hi everybody, i am having a problem at curve fitting function,
    i take at output, what i give as input, where do i make mistake?
    at example i give 4 values, if i enter 6 values it works, but i need to do it with 4 values.
    any ideas?
    thanks
    Solved!
    Go to Solution.
    Attachments:
    curve fitting.vi ‏16 KB

    Your function is a simple quadratic polynomial, so you should use the general polynomial fit function instead. Don't overcomplicate things
    LabVIEW Champion . Do more with less code and in less time .

  • Curve fitting sin*Exp

    Hi,
    I have a few questions,
    1- Can I put my initial guesses to the `curve fitting express` via an array control instead of editing each time the express itself?
    2- I have trouble with the fitting of my signal. it`s far beyond my initial guesses. I tried playing with the numbers and it seems when I put the right numbers in the function instead of using the parameters, the fitting is perfect, but when I put the same numbers as initial guesses I don`t get even close to data fitting, instead I get most of my signal as a residual.can someone help?
    3- the fitting itself takes ages, is there any way to make it faster?
    SubVI, and the text data file attached.
    thanks.
    Attachments:
    Untitled 12.vi ‏155 KB
    testing1.txt ‏114 KB

    You are trying to fit
    y(x)=a*cos(b*x)*cos(c*x)*exp(d*x)+e
    with [a, b, c, d, e] as adjustable parameters. This seems like a poorly defined model, for example you will have an equally good solution swapping b and c. Also from looking at the data, d should be negative, yet you give it a large positive value as guess. Periodic functions such as "cos" (I am not sure why you use "sin" in the title of the post) are always problematic, because you can fit equally well to an alias frequency by mistake. You need to be absolutely sure about good initial guesses here. Is the model really sufficient? For example, you don't account for possibe phase.
    Your file also does not contain enough significant digits, so there are multiple x values for each y. It seems however, that the x-values are linearly spaced, so it is possible to approximate the real x ramp (see attached).
    Anyway, to your question. You can skip the express VI and use "nonlinear curve fit" instead. If speed is a concern, you should use the VI model, which is pretty simple in this case. (fitting takes much less than a second)
    Aristofel wrote:
    ... I tried playing with the numbers and it seems when I put the right numbers in the function instead of using the parameters, the fitting is perfect,...
    Is this synthetic or real data? As a first step, you should generate fake data with known parameters and see how well the fit does if the estimates are somewhat off.
    What are the "right numbers" in this case?
    In any case, Your problem is probably better solved using e.g. a fourier transform. You should get two lorentzian peaks with the midpoint between the two related to (b) the separation between the two related to (c) and the lorentzian width related to (d). Your data gives a much more complex transform, so your model seems way too simplistic for your data anyway.
    Can you give us a bit more background on the origin of the data, the physics behind it, and the model?
    Attached is a literal translation of your VI to the plain "VI model" fitting. Still, nonlinear fitting seems to be the wrong choice for this problems as outlined above.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SinExp.zip ‏55 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

  • Constrained Nonliner Curve Fit Error -20003 help

    Hello.
    I use Constrained Nonliner Curve Fit.vi to fit a customed function, just in the following picture 1. The initial paraments are exactly right, but it always stopped by a error -20003,it says "The number of samples must be >0",just as the picture 2.
    What should I do to correct it? Thanks!
    Attachments:
    1.png ‏32 KB
    2.png ‏9 KB

    Can you attach your code and some sample data? How big is the [X] array? The [a] array?
    Does it work if you remove the partial derivatives calculation? (LabVIEW will automatically substitute numerical derivatives).
    (The way you index into [a] seems incredibly convoluted. Couldn't you simply reshape into four columns and autoindex on a FOR loop?)
    LabVIEW Champion . Do more with less code and in less time .

  • When creating a new DPS should I use sizes offered by InDesign or the display size of the device?

    Hello all,
    When creating a new DPS, should I use the sizes offered by InDesign or the display size of the device?  I ran into this question when I was looking up the sizes of different devices and found that iPhone 5s, iPhone5c, and iPhone4s sizes differ than the defauly dimensions offered by InDesign. 
    Also, should I worry about the ppi resolution?  With iPhone, they all seem to be 326ppi but when dealing with other devices is this something that I should take into consideration?  Ideally, I could be creating DPS apps for all devices offered in the Digital Publishing drop down in InDesign (iPhone, iPad, Kindle Fire/Nook, and Android).
    Thank you for any help you can provide.
    By the way, if it helps I am using InDesign CC.

    Using 1024x768 and creating PDF articles will get you OK with both iPad resolutions, and, as Bob L. says, quite decent "one size fits all" result for all other devices.

Maybe you are looking for