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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 How to input piecewise function when fitting data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Meilongwei

China
5 Posts

Posted - 04/15/2015 :  01:00:30 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

AmandaLu

439 Posts

Posted - 04/15/2015 :  06:44:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - AmandaLu on 04/15/2015 06:51:15 AM
Go to Top of Page

Meilongwei

China
5 Posts

Posted - 04/15/2015 :  10:55:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000