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
 problem with Nonlinear Least Squares Fitter

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
jonni Posted - 01/19/2003 : 3:13:01 PM
I'm trying to do NLSF but I have problem

my steps what i did:
using Origin7
1. I built new function using code builder:
-------------------------------------
#include <origin.h>
#include <NAG\OCN_s.h>
double psi(double x)
{
return nag_real_polygamma(x,0);
}
-------------------------------------
this function works very good.
2. I made a "New function" in Origin:
y=-(psi(1/2+0.0174/x)-psi(1/2+0.0071/x)-ln(0.0174/0.0071)),
created Worksheet of this function.
3 I tried to fit this worksheet using NLSF and following
function:y=-P1*(psi(1/2+0.0174/x)-psi(1/2+0.0071/x)-ln(0.0174/0.0071))+P2;
4. result is very bad,it is very far from P1=1 and P2=0.

I can not even to fit exact function.
What should I do??

I can show the graph with my fitting.

Evgeniy
12   L A T E S T    R E P L I E S    (Newest First)
jonni Posted - 01/21/2003 : 3:20:03 PM
Dear Easwar

It looks like the problem is solved!!!!!!!
It is vvvvveeeeeeeeeeryyyyyyyyy smart.

thank you a lot!!!!!!

what is your advise where I should be careful with the same in future??

I think it will be usfull to know it for people who also use NLSF+origin c

Evgeniy

PS we ordered Origin7 :)
easwar Posted - 01/21/2003 : 10:35:03 AM
Hi Evgeniy,

Here is the problem:

You defined your NLSF function using Origin C as:
y=-P1*(psi(1/2+0.0174/x)-psi(1/2+0.0071/x)-ln(0.0174/0.0071))+P2;

Origin C uses C syntax, and so the fraction 1/2 is zero and not 0.5 and so you need to define your function as:

y=-P1*(psi(1.0/2.0+0.0174/x)-psi(1.0/2.0+0.0071/x)-ln(0.0174/0.0071))+P2;

I tried the above and it works fine.

Easwar
OriginLab.

jonni Posted - 01/20/2003 : 5:03:14 PM
I did all what you suggested, before. Previous my graphs is the result of it.

I need to fit black curve at graph2, black curve at graph2 is real one.

Can you send to me your results of simulation and fitting if you have result of simulations and fitting the same as black curve on graph2?
Real function: for x<<1 aproximatly eq x^2
for x~1 aproximatly eq ln(x)(you can see it on graph 2; black curve)
But all curves, what fitting session generats, look as liniar, you can easely see it on graphs (red curves)

I need to fit my black curve on graph2!!!!!!!!!!!!!!!!!!
it is real one.

You write:
>5> At this point, you can use NLSF simulate etc. to generate your
>data with values assigned for P1, P2 etc. and then fit them and you
>will be able to get a fit that looks like your graph1 and not like
>your graph2.

it is wrong! I need fit curve as black one at the last graph2.


Many thanks for your help

Evgeniy


Edited by - jonni on 01/20/2003 5:18:02 PM
easwar Posted - 01/20/2003 : 4:27:48 PM
Hi Evgeniy,

First of all, if you define one single function inside NLSF where you also include the NAG call right in that function, it works fine for you. So that can be your solution for now.

If you really want to define a psi(x) function outside of NLSF and then use it in NLSF to define your fitting function, then please follow all of these steps:

1> define your psi(x) function in code builder, outside of NLSF, by creating a file, say psi.c, and place it in the Origin C subfolder:

#include <origin.h>
#include <NAG\OCN_s.h>

double psi(double x)
{
return nag_real_polygamma(x,0);
}

2> make a header file, called psi.h, and place it under the \OriginC\system subfolder. The header file should have just one line as below:

double psi(double x);

3> change the nlsf.fit template in the \OriginC\NLSF subfolder so that it has the psi.h header file included - add these lines at the beginning with other header entries, and keep the others

#include <NAG\OCN_s.h>
#include <psi.h>

4> define a new NLSF function (the new template should show when editing in code builder from NLSF):

y=-P1*(psi(1/2+0.0174/x)-psi(1/2+0.0071/x)-ln(0.0174/0.0071))+P2;

5> At this point, you can use NLSF simulate etc. to generate your data with values assigned for P1, P2 etc. and then fit them and you will be able to get a fit that looks like your graph1 and not like your graph2.

6> If you are having further problems, please send your files to your local tech support office.

We are making improvements to the integration of NLSF and OC so that in a future version it will be much easier to add header files and sub functions right inside your NLSF function definition.

Easwar
OriginLab.

jonni Posted - 01/20/2003 : 3:07:59 PM
this is the first graph where i plot data seimulated by fitting session and very good fit.



second graph is, data produced by my psi function and very bad fit


Black one it is psi function - it is real one becous I know how it has to be. Red one it is the function generated by fitting seesion during fitting(very similar to previous one.)

You can see the result: fitting session generate wrong data.

what to do??

Edited by - jonni on 01/20/2003 3:11:05 PM

Edited by - jonni on 01/20/2003 3:11:54 PM
jonni Posted - 01/20/2003 : 2:20:50 PM
lets continue..........

the main problem is that fitting session generate in wrong way my function. and the resalt is, if you will simulate data by fitting session you will have good fitting, if you will generate data by function plot you will have right!!!(i can easely see it) data, but not able to fit it becous of wrong generation of data by fitting program.......
easwar Posted - 01/20/2003 : 11:12:37 AM
Hi Evgeniy,

I tried defining the function psi(x) in a separate OC file in Code Builder, as follows:
double psi(double x)
{
return nag_real_polygamma(x,0);
}

and once I compiled and linked, I could plot this function just fine using the normal function plot. So I am not sure what the issue is.

As for using this external function in an NLSF function, you will need to have a header file that prototypes this function, and will need to add the header file in your NLSF function definition (template). Is that what you are having trouble with?

Your local tech support office is listed on this page, at the bottom:
http://www.originlab.com/www/services/europe.asp

Easwar
OriginLab.


blankuser Posted - 01/20/2003 : 10:58:31 AM
XA-XA-XA-XA-XA-XA-XA

It is very nice.
I repited everything what you did.
And I have very good fitt, BUT!!!!!!
Have you seen befor how does the y = -P1 * ( nag_real_polygamma(1/2 + 0.0174/x, 0) - nag_real_polygamma(1/2 + 0.0071/x, 0) - ln(0.0174/0.0071) ) + P2; look like???
Try just to plot my function in my way but do not use simulation from your fitting session, use just normal function plot.
First you have to build new function in code builder to use it as build in functions.
And you will see.

Thaks for your time and help

Evgeniy

Edited by - on 01/20/2003 11:01:21 AM
blankuser Posted - 01/20/2003 : 10:49:29 AM
what is the address of my local techsupport?

my location is:
-----------------------
University of Exeter
Exeter
Devon
United Kingdom
-----------------------
easwar Posted - 01/20/2003 : 10:43:05 AM
Hi,

I defined a new NLSF function with the expression that I posted before, which includes the nag_real_polygamma() call direclty in the expression of the function. I then used the Action->Simulate menu in NLSF to create a dataset with P1=1, P2=0, and x ranging from 0 to 1. I then used the same function to fit to the dataset that was generated. And it works fine for me.

Did you try combining the two functions? If you have more problems with this, and need further help, please send your FDF, OPJ, and other relevant files to your local tech support office.

Easwar
OriginLab.


blankuser Posted - 01/20/2003 : 10:39:10 AM
question: how you can use your formula to simulate data???
I have to build new function in code builder to use it in origin as build-in function, otherwise I can't use functions from nag library as built-in function.

What I did: Using my function psi(as I already described above) I simulated the data(with P1=1,P2=0). Then, I used your formula:
y = -P1 * ( nag_real_polygamma(1/2 + 0.0174/x, 0) - nag_real_polygamma(1/2 + 0.0071/x, 0) - ln(0.0174/0.0071) ) + P2; as fitting function at interval x=(1..30).
Result is the same: fitting parameters are very far from P1=1,P2=0.

My intrest is at region x=(0..1);

What is wrong?

Edited by - on 01/20/2003 10:42:15 AM
easwar Posted - 01/20/2003 : 10:08:32 AM
Hi Evgeniy

I tried a simplified version of your function, by combining the two functions as below:

y = -P1 * ( nag_real_polygamma(1/2 + 0.0174/x, 0) - nag_real_polygamma(1/2 + 0.0071/x, 0) - ln(0.0174/0.0071) ) + P2;

I then used this function in Simulate mode in NLSF and generated a dataset with P1=1 and P2=0 for x range from 1 to 30. I could then fit the simulated data just fine.

What x range are you using? Also, it is not clear how you are accessing one function from the other. Maybe you can post more details, or try combining the functions like I have posted above?

Easwar
OriginLab.


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