T O P I C R E V I E W |
Meilongwei |
Posted - 04/15/2015 : 01:00:30 AM Dear all: I want to fit some data with my own piecewise function as follows: y=a*x^2+b/x+c*x+d (if x>0.1) y=a*x^2+b/(x^2+1)+c*x+d (if x<=0.1)
Here a, b, c, d are the parameters I want to calculate with origin. How do I input it in self-defined function dialog? I tried the code as follows:
if(x>0.1) y=a*x^2+b/x+c*x+d else y=a*x^2+b/(x^2+1)+c*x+d
But it could not be compiled. Can any body help me? Thanks a lot! Longwei
meilongwei |
2 L A T E S T R E P L I E S (Newest First) |
Meilongwei |
Posted - 04/15/2015 : 10:55:48 AM quote: Originally posted by AmandaLu
Hi Weilongwei,
You can define the piecewise function in OriginC. With Fitting Function Organizer opened, select Origin C for Function Form and define the fitting function in Code Builder
void _nlsfpiecewise( double xc, double a, double b, double c, double d, double x, double& y) { if(x>xc) { y=a*x^2+b/x+c*x+d; } else { y=a*x^2+b/(x^2+1)+c*x+d; } }
Here is a tutorial you can follow: http://www.originlab.com/doc/Tutorials/Fitting-Piecewise
If you define the function in Fitting Function Builder, please don't forget to put semicolon at the end of every command.
Thanks, Amanda OriginLab Technical Service
Thanks a lot! It works now!
meilongwei |
AmandaLu |
Posted - 04/15/2015 : 06:44:12 AM Hi Weilongwei,
You can define the piecewise function in OriginC. With Fitting Function Organizer opened, select Origin C for Function Form and define the fitting function in Code Builder
void _nlsfpiecewise( double xc, double a, double b, double c, double d, double x, double& y) { if(x>xc) { y=a*x^2+b/x+c*x+d; } else { y=a*x^2+b/(x^2+1)+c*x+d; } }
Here is a tutorial you can follow: http://www.originlab.com/doc/Tutorials/Fitting-Piecewise
If you define the function in Fitting Function Builder, please don't forget to put semicolon at the end of every command.
Thanks, Amanda OriginLab Technical Service |
|
|