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
 Fitting 2 equations to different ranges of x
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

CMcRitchie

United Kingdom
3 Posts

Posted - 07/28/2016 :  08:37:47 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I wondered if it was possible to use the Fitting Function Organiser in the following way:

Using x,y data where 0<x<2000

Create a function that applies two or more equations to the experimental data over different ranges of x

e.g. Equation 1: y = a + (b*x) where 0<x<40

Equation 2: y = a + (b*x) where 40<x<2000

I know I can manually select different parts of the experimental data and apply each function in turn, however it would be really beneficial for me if this could be done using a user created function.

Any help would be much appreciated,

Thanks

Hideo Fujii

USA
1582 Posts

Posted - 07/28/2016 :  09:50:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi CMcRitchie,

I think you can consider the built-in functions in the Piecewise category such as PWL2 for two segments
(or PWL3 for three segments):

http://www.originlab.com/doc/Origin-Help/PWL2

Please take a look.

--Hideo Fujii
OriginLab
Go to Top of Page

CMcRitchie

United Kingdom
3 Posts

Posted - 07/28/2016 :  10:06:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Hideo Fujii

Hi CMcRitchie,

I think you can consider the built-in functions in the Piecewise category such as PWL2 for two segments
(or PWL3 for three segments):

http://www.originlab.com/doc/Origin-Help/PWL2

Please take a look.

--Hideo Fujii
OriginLab



Hi Hideo Fujii,

Thanks for your suggestion. Do you know if there is a similar alternative that would accommodate non-linear functions?

Thanks,

CMcRitchie
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 07/28/2016 :  10:48:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi CMcRitchie,

> Do you know if there is a similar alternative that would accommodate non-linear functions?

Currently, there is no built-in piecewise non-linear functions. So, you need to make a user-defined function
generally in the following way:
y0=function1(x0);
if( x<x0 )  y=function1(x);
else	    y=function2(x); //function2 is a curve which passes (x0,y0) to connect to function1

The hard (if not impossible) part may be to find the form of function2 by solving y0=function2(x0) analytically.

Good luck.

--Hideo Fujii
Go to Top of Page

CMcRitchie

United Kingdom
3 Posts

Posted - 07/28/2016 :  10:59:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Hideo Fujii

Hi CMcRitchie,

> Do you know if there is a similar alternative that would accommodate non-linear functions?

Currently, there is no built-in piecewise non-linear functions. So, you need to make a user-defined function
generally in the following way:
y0=function1(x0);
if( x<x0 )  y=function1(x);
else	    y=function2(x); //function2 is a curve which passes (x0,y0) to connect to function1

The hard (if not impossible) part may be to find the form of function2 by solving y0=function2(x0) analytically.

Good luck.

--Hideo Fujii




Again thanks for your help. I have started to play around with using 2 equations, if I were to introduce a third equation, what do I write as the code to introduce an additional condition on the range of x? i.e. go from PWL2 to PWL3

e.g.

if (x<x0) y=function1(x);
if (x0<=x<=xa) y=function2(x);
else y=function3(x);

what is the correct command for the 2nd line? I assume repeating "if" is not correct.

Many thanks,

CMcRitchie
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 07/28/2016 :  11:15:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi CMcRitchie,

> if (x<x0) y=function1(x);
> if (x0<=x<=xa) y=function2(x);
> else y=function3(x);
> what is the correct command for the 2nd line?
> I assume repeating "if" is not correct.

The syntax should be like (assuming function type is Origin C):
if(x<x0)      y=function1(x);  //x<x0
else if(x<xa) y=function2(x);  //x0<=x<xa
else          y=function3(x);  //xa<=x
Hope this helps.

--Hideo Fujii
OriginLab

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