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
 Origin Forum
 How to input piecewise function when fitting data

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
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

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