The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Nonlinear constraints for custom fitt funct

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
millot.marius Posted - 09/06/2012 : 6:50:09 PM
Origin 8.5.1 win vista

Hi

I d like to fit a dataset with a piecewise function being quadratic up to threshold_1, cubic between threshold1 and threshold2 and again quadratic above threshold2

However the piecewise fitting function must be continuous as well as its first derivative

I tried ti define the function like this


// 
void _nlsfTestFitPiecewise(
// Fit Parameter(s):
double a0, double a1, double a2, double b0, double b1, double b2, double b3, double c0,
double c1, double c2, double d0, double d1,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	// Beginning of editable part
	if (x<d0)
	y = a0+a1*x+a2*x^2;
	else 
		if (x<d1)
	y = b0+b1*x+b2*x^2+b3*x^3;
	else 
		y=c0+c1*x+c2*x^2;
		
		
	// End of editable part
}


This works fine but i don't know how to implement the continuity of the function and its derivative that is to say the following constraints


a0+a1*d0+a2*d0^2=b0+b1*d0+b2*d0^2+b3*d0^3;
a1+2*a2*d0=b1+2*b1*d0+3*b3*d0^2;
c0+c1*d1+c2*d1^2=b0+b1*d1+b2*d1^2+b3*d1^3;
c1+2*c2*d1=b1+2*b1*d1+3*b3*d1^2;

2   L A T E S T    R E P L I E S    (Newest First)
millot.marius Posted - 09/07/2012 : 12:37:54 PM
Thank you Sam, this works!

Sam Fang Posted - 09/07/2012 : 05:10:50 AM
You can use meaningful parameters, and in this way nonlinear constraints are not necessary. e.g.


threshold_1: d0
y value at threshold_1: b0
derivative at threshold_1: k0
threshold_2: d1
y value at threshold_2: b1
derivative at threshold_2: k1

two extra parameters:
parameter for the first quadratic: a
parameter for the second quadratic: c


Use parameters a, d0, k0 to define the first quadratic.
Use parameters c, d1, k1 to define the second quadratic.
Use parameters d0, k0, d1, k1 to define the cubic.

Fitting Function can be defined as follows:
-------------------------------------

  if( x<d0 )
    y = b0 + k0*(x-d0) + a*(x-d0)^2;
  else if( x <d1 )
    y = b0*(x-d1)/(d0-d1) + b1*(x-d0)/(d1-d0) + (k0-(b1-b0)/(d1-d0))*(x-d0)*(x-d1)^2/(d0-d1)^2
      + (k1-(b1-b0)/(d1-d0))*(x-d0)^2*(x-d1)/(d1-d0)^2;
  else
    y = b1 + k1*(x-d1) + c*(x-d1)^2;

-------------------------------

You can apply a constraint:
d0 < d1

Sam
OriginLab Technical Services

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000