LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set parameter to be positive in curve fitting

Solved!
Go to solution

Dear all

 

I am using "curve fitting "  VI to fit my experiment data.

The nonlinear model  is  y=0.5642*(1+b*(2*(x-c)^2-1))*exp(-((x-c)^2)), where "b" and "c" are two parameters.

 After fitting, the parameter "b" sometimes is negative. But I need to set "b" only to be a positive number. However, there is no such option in the curve fitting VI,   as shown in the  attached figure.

How can I realize this?  

Any expert can help me? Thank you very much in advance!

0 Kudos
Message 1 of 5
(3,568 Views)

Put an absolute value on the output for b from the curve fit.

Tim
GHSP
0 Kudos
Message 2 of 5
(3,563 Views)
Solution
Accepted by topic author ereerre

Substitute b=exp(d) into your equation: y=0.5642*(1+exp(d)*(2*(x-c)^2-1))*exp(-((x-c)^2))

 

Fit for d and c, then calculate b=exp(d).   The program can fit d positive or negative while b is alway positive.

 

-- James

Message 3 of 5
(3,556 Views)

Many thanks to aeastet!
 I have tried, but I can not put an absolute value on the output for parameters in  "curve fitting" VI
There is no such option in the setting of the VI.
If I use  y=0.5642*(1+abs(b)*(2*(x-c)^2-1))*exp(-((x-c)^2)), it was prompted that the grammar was wrong.

 

 

 

 Also many thanks to  drjdpowell !
Your suggestion really works.
Thank you so  much for your kind help!

0 Kudos
Message 4 of 5
(3,538 Views)

By the way, you can extend this to put different constraints on b than b>0:

 

b > m    -->   use b = m + exp(d)

b < n     -->   use b = n - exp(d)

 

and for both high and low limits you can make use of the arctan function that is always between -pi/2 and +pi/2:

 

m < b < n    -->   use b = m + (n-m)(atan(d) + pi/2)/pi

 

-- James

0 Kudos
Message 5 of 5
(3,522 Views)