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 for Programming
 Forum for Origin C
 Parameter initialization within a NLSF loop
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

hauli

Austria
Posts

Posted - 11/14/2006 :  03:03:47 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System: Windows XP

Dear All,

I am using a user defined equation (named logECF) that has 3 parameters; one parameter should vary from 5 to 95 step 5 and is fixed during the fit as in the code below.

The problem is concerned with parameter initialization: as the equation is very sensitive to good initial values, I want to use the fitting results of the first loop to be used as the initial values for the second loop, the results of the second loop as initial values for the third loop, and so on.

my second question is how to apply correctly to the fitting result of the (let's say) 7th loop, i.e the value of NLSF.p3 of the 7th loop?

void test()
{
int FF;
for (FF=5; FF<=95; FF+=5)
{
using NLSF = LabTalk.NLSF;
NLSF.Init();
NLSF.Begin();
NLSF.Func$="logECF";
NLSF.FitData$="Data1_B";
NLSF.p1=0.3;
NLSF.p2=FF;
NLSF.p3=-3;
NLSF.v2=0;
NLSF.IterateEx(100);
NLSF.IterateEx(100);
NLSF.ParamWks();
NLSF.PasteParams("P");
NLSF.KeepParam=1;
NLSF.End(4);
}
}

Thanks for any suggestions

Hauli

zachary_origin

China
Posts

Posted - 11/14/2006 :  04:08:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Hauli,

How about this? Add some vectors to record all the fitted parameters?
I rewrote the function, is this what you wanted?


void test()
{
// int FF;
vector vP1(20), vP2(20), vP3(20);//these vectors will record the fitted paramters.
int ii;
for (ii=1; ii<=19; ii++)
{
using NLSF = LabTalk.NLSF;
NLSF.Init();
NLSF.Begin();
NLSF.Func$="logECF";
NLSF.FitData$="Data1_B";
if (ii == 1)
{
NLSF.p1=0.3;
NLSF.p2 = ii*5;//NLSF.p2=5; ??
NLSF.p3=-3;
}
else
{
// fitted parameter value in last loop, because ii starts as 1,
//so it is not ii-1 but ii-2;

NLSF.p1 = vP1[ii-2];
NLSF.p2 = vP2[ii-2];
NLSF.p3 = vP3[ii-2];
}
NLSF.v2=0;
NLSF.IterateEx(100);
NLSF.IterateEx(100);
NLSF.ParamWks();
NLSF.PasteParams("P");
NLSF.KeepParam=1;
NLSF.End(4);
//After fitting, record the paramters.
vP1[ii-1]=NLSF.p1;
vP2[ii-1]=NLSF.p2;
vP3[ii-1]=NLSF.p3;
}

//then you can use the fitted paramters for any loop by the parameter vectors.
double aa = vP3[6];//P3 for the 7th loop.
}


But I still do not think this is a good method for the problem. If the equation is very sensitive to initial values, you'd better write a piece of initial code for the equation. You can reference a similar build-in function to write it. If you have any problem for the code, you can post your equation here and we will try to write it for you.



Zachary
OriginLab Technical Services.

Edited by - zachary_origin on 11/14/2006 04:11:19 AM
Go to Top of Page

hauli

Austria
Posts

Posted - 11/14/2006 :  05:57:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Zachary,

I tried your code, thank you for that.
it performs 19 consecutive fits (as I want)
but unfortunately with NLSF.p2 always fixed to 5.
Any idea?

I will try to use your suggestion and write a piece
of initial code for the equation

Hauli

Go to Top of Page

zachary_origin

China
Posts

Posted - 11/14/2006 :  08:43:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sorry, I have not looked carefully into the code you wrote. Have you noticed that there is a line "NLSF.v2 = 0;"? you can see from Origin Programming Help:

nlsf.vn : Tells whether parameter n is fixed or allowed to vary during fitting: 1 = vary, 0 = fixed. (You can fix a parameter using linear constraints.)

I think you must have used the options wrong. It should be NLSF.v2 = 1;. In fact, by fault the parameter will be allowed to vary without any specification.

Another thing is why you use NLSF.IterateEx(100) twice? you can replace it with NLSF.IterateEx(200).

Zachary
OriginLab Technical Services.
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