From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Non Linear Curve Fitting

Solved!
Go to solution

Dear All,

I am using the Non Linear Curve Fitting Lev-Mar :formula string , but I have some problem for the syntax of the model description function.

I have written as follow :   U*(exp((-t+td)t1)-exp((-t+td)/t2)

where U, t1, t2, td,are the parameters, x as a variable ,t is the time and exp is exponential function.The Error which i getting is : (Hex 0xFFFFA5D1) Wrong letter or undefined variable in the formula.

In case if i use model description funtion as a a1+a2*x+a3*x^2  (given in help where a1,a2,a3 as a initial parameters and x as  variable ,fot this i am not getting any errors.

But as per my requirement i need to fit  U*(exp((-t+td)t1)-exp((-t+td)/t2).

 

Thanks for all the suggestions and help.

0 Kudos
Message 1 of 14
(3,501 Views)

Check here for the syntax requirement, especially the variable names.

 

(For performance and easy of graphical programming, I recommend to use the VI model anyway.)

0 Kudos
Message 2 of 14
(3,478 Views)

Hai Altenbach,

             I changed the varibles names as you said.Still there is a problem . Please let me know why these errors are coming. I am attaching my VI.

 

Thanks you..

0 Kudos
Message 3 of 14
(3,435 Views)

Please save your VI with typical default values in all controls so we can actually test. Why don't you wire reasonable initial guesses? It is unlikely that the Y values provide reasonable guesses. Also the "length" needs to be matched to the number of parameters. Do you do that?

 

Clusters are just a mess. Why do you have "t" as independent variable AND parameter in (2)? Why does your formula not even contain "x" in (1)?

 

(... and please don't save it with the front panel and diagram maximized to the screen! Very annoying)

 

As I said, why don't you use the VI model? Much simpler and faster!

0 Kudos
Message 4 of 14
(3,422 Views)

Looks like you got the variable naming right, but the model is not well formed. For model description 1 you have "x" as your domain, but the variable "x" does not appear in your model. You have also defined a2 as a variable, but it is also not used in the model. I'm guessing your domain variable is "t" from your original post, so you might try the following model description:

model: u*(exp((-t+t3)/t1)-exp((-t+t3)/t2))

Parameters: u, t1, t2, t3

x: t

A variable should either appear in the 'Parameters' array or as 'x' in the model description, but not in both. All variable names ('Parameters' and 'x') should be used in the model.

 

Unfortunately the formula string syntax is somewhat limited and the error information does not do a good job of giving you useful feedback about a given problem. If possible you might consider using the VI reference interface to Nonlinear Curve Fit.vi. In addition to better performance it gives you edit-time feedback about whether your model is executable or not and allows for much better debugging.

-Jim

0 Kudos
Message 5 of 14
(3,420 Views)

The model description I showed should get you past the parsing problems but I was unable to get any further because of all the reasons Christian already mentioned.

-Jim

0 Kudos
Message 6 of 14
(3,415 Views)

Sorry for inconvenient Altenbach. The "length" is matched to the number of parameters.

 

I made some changes in the attached VI. As i said the curve should start from zero. But i am not getting it.

I am attaching a image which The formula i wants to implement.

 

Please send me a link about VI Model..

Thank you for Reply...  

Download All
0 Kudos
Message 7 of 14
(3,392 Views)

 Hai DSPGuy...

        The model description as you said is working without any errors . But the thing is the graph should be starts from zero. Curve should starts from zero and decrease gradually in the negative order.

  

 

 

Download All
0 Kudos
Message 8 of 14
(3,390 Views)

Your documentation has the solution to your problem. Initial guesses are very far off, but LV Equation.png has information at the bottom about how to set 3 of your 4 parameters. I'd suggest the following:

1. Plot your data on an x-y graph so you can see the scale of your domain.

2. Plot the curve formed using your initial guess parameters on the same graph as your data.

3. Adjust initial guess parameters until starting point looks reasonable.

4. Curve fit.

 

-Jim

0 Kudos
Message 9 of 14
(3,373 Views)

Christian Altenbach has a very nice set of examples and helpful information here:

https://forums.ni.com/t5/Nonlinear-Fitting/gp-p/grp-1617

You may find example 3 in the practical nonlinear fitting topic relevant.

-Jim

Message 10 of 14
(3,363 Views)