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 for Programming
 Forum for Origin C
 Origin C function for NLSF

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
espenhjo Posted - 11/17/2003 : 06:47:31 AM
Hi,
I am making a function in Origin C that is to be used in NLSF. I have called it parplane. The actual function builds a damped oscillating curve that is a sum of n equations. I have declared this in dSum. For each part in dSum roots exist that have to be found. These are found in the while loop and ascribed to rtn[i].

The parameters that are to be found with NLSF are a, I0 and C, from which a is the interesting one. The variable of the datasets is q.
Now, a exists both in the rootfinding function and in dSum. Have I set up the script correctly so that NLSF optimalizes both the fit and the roots?

Here is the script:

#define JMAX 50
#define xacc 1e-12
#define nr_roots 100 //number of roots to be found

double parplane(double a, double q, double I0, double C) //function for use in NLSF
double dSum = 0; //cumulative output set to zero

//void newt02()
//{
double rtn[nr_roots],x1[nr_roots],x2[nr_roots],fx[nr_roots],df[nr_roots],dx[nr_roots];
int j;
int i = 0;

//these guess for the range in which a root exists could come from a
//bracketing and bisection algorithm

while (i < nr_roots)
{
x1[i] = (i+1)*PI-1;
x2[i] = (i+1)*PI+1;

rtn[i] = 0.5*(x1[i]+x2[i]); //first guess as the midpoint of the interval [x1,x2]

for (j=1;j<JMAX; j++)
{
fx[i] = rtn[i] * tan(rtn[i]) / a; //the function with roots
df[i] = tan(rtn[i]) / a + rtn[i] * (1+tan(rtn[i]) * tan(rtn[i])) / a; //first derivative of the function

dx[i] = -fx[i]/df[i];
rtn[i] += dx[i];

printf("%e\n", dx[i]);

if ((x1[i]-rtn[i])*(rtn[i]-x2[i]) < 0.0){
printf("error, jumped outside bounds");
exit(1);}
if (fabs(dx[i]) < xacc){
printf("found root after %d attempts, at %lf\n", j, rtn[i]);
i++; //exit(0);
break;}
if (j = JMAX - 1){
printf("error - exceeded max tries no root");
i++;
break;}
}
}
//exit(0);
//}
for (int k = 0; k < nr_roots; k++)
{
dSum += exp(-(rtn[k]^2) / (a^2)) * 2 * (1 + sin(2*rtn[k])/(2*rtn[k]))^(-1) * ((2*PI*q*a)*sin(2*PI*q*a)*cos(rtn[k])-rtn[k]*cos(2*PI*q*a)*sin(rtn[k]))^2 / ((2*PI*q*a)^2-rtn[k]^2)^2 ;
}
return I0 * dSum +C ;
}


Thanks!

Espen

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