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
 Complex numbers in NLSF
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

koloditv

Japan
Posts

Posted - 06/21/2004 :  05:21:00 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Dear all,
I wonder if you had any experience with NLSF curve fitting using a custom-defined function containing COMPLEX numbers i.e., i*i=-1? There is no problem to do it in MatLab, but how about Origin? I would really appreciate your help.

Taras

easwar

USA
1964 Posts

Posted - 06/21/2004 :  11:49:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Taras,

If you have version 7.0 or higher, you can define NLSF fitting functions that make use of Origin C code. Origin C supports complex arithmetic. However, the function needs to return a double for NLSF to fit.

Could you post more details of your function, and what exactly you want to fit? We could then provide more details, or come up with an example for you.

Easwar
OriginLab

Go to Top of Page

koloditv

Japan
Posts

Posted - 06/21/2004 :  11:07:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Easwar,
Yes, I have version 7.5 of Origin.
I'm trying to fit an experimentally obtained far infrared reflection spectrum, R(w), where "w" is independent variable (i.e., frequency) to a model function, R, defined by:

R=abs((sqrt(epsilon)-1)/(sqrt(epsilon)+1)).

In its simplest form, "epsilon" is a complex number given by:

epsilon=P0*(wl1*wl1-w*w-gl1*i*w)*(wl2*wl2-w*w-gl2*i*w)*(wl3*wl3-w*w-gl3*i*w)/(wt1*wt1-w*w-gt1*i*w)*(wt2*wt2-w*w-gt2*i*w)*(wt3*wt3-w*w-gt3*i*w),

where PO, wl1..wl3, gl1..gl3, wt1..wt3, gt1..gt3 are adjustable parameters, and "i" indicates imaginary part of the complex number (e.g., i*i=-1).

I wonder how I can use Origin to fit my experimental data to the model R(w) function. Unfortunately, I'm not good at C programming. Any detailed advise would be appreciated.
Thanks,
Taras

Go to Top of Page

easwar

USA
1964 Posts

Posted - 06/22/2004 :  5:40:57 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Taras,

It is possible to do what you want to do. Here is the procedure on (much simplified version) how to do it:

1> I presume you have data in two columns, say called w and R, in a worksheet - graph this data
2> With the graph active, bring up the NLSF tool using the menu command Analysis->Nonlinear Fitting

In the NLSF tool:
3> Select the menu item Function->New to start defining a new function
4> Give the function a name
5> Leave the Type drop-down as User-Defined
6> In "Parameter Names" edit box, enter parameter names of
P0, w1, g1
Note: I am using only three parameters in this example - you need to expand this
7> For Indep Var, enter w
8> For Dependent Var, enter R
9> Make sure the "Use Origin C" checkbox below the edit box is checked
10> Click on the "Edit in Code Builder" button. This will open Code Builder with your fitting function in a window
11> Scroll all the way to the top of the fitting function text, and add an additional include file to the list of include files already there:
#include <complex.h>
12> Scroll down to the "editable" part towards the end, and within the white editable area, enter the following lines of code:

complex epsilon = P0 * (w1 * w1 - w * w - g1 * 1i * w);
R = cabs( ( sqrt(epsilon) - 1) / ( sqrt(epsilon) + 1 ) );


Note: To use i for creating compled numbers, you need to write this as "1i" like in the first line above.
Abs function for complex numbers is cabs()
13> Click the Compile button - you should get no errors in the Code Builder output window
14> Click the "Return to NLSF" button to get back to Origin and NLSF
15> Click the Save button to save your function definition
16> Click the Fit button (after assigning datasets to w and R as necessary) and proceeed with your fit.

If you run into problems, please contact tech support with your data and your fitting function (FDF file). Please refer to this forum post in your message to them.

Easwar
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