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
 fit to a function with origin c and nag

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
michaelbecker Posted - 05/20/2008 : 07:33:17 AM
Origin Version: OriginPro 8GSr1
Operating System: Win XP

Hello,

I have data which can be fitted to:

The integration is from 0 .. 2pi.

I tried to implement this as a user-defined fit function in OriginC.
Here is my code:

 
#pragma warning(error : 15618)
#include <origin.h>
#include <OC_nag8.h>

void test () {
double f;
_nlsfKraftPM (1,10,f); //berechne F(10) mit k = 1
printf("test %f",f);
}

double NAG_CALL integrand(double phi) {
double a = 0.06;
double b = 0.06;
double ta = 0.06;
double tb = 0.06;
double c=sqrt(a^2 + b^2 - 2 * a * b * cos (phi));
double d = (h + ta + sqrt(c^2 + (h+ta)^2)) * (h + tb + sqrt(c^2 + (h+tb)^2));
double e = (h + sqrt(c^2 + h^2)) * (h + ta + tb + sqrt(c^2 + (h+ta+tb)^2));
return cos(phi) * ln(d/e);
}

void _nlsfKraftPM(
// Fit Parameter(s):
double k,
// Independent Variable(s):
double h,
// Dependent Variable(s):
double& F)
{
// Beginning of editable part

const double a = 0.06;
const double b = 0.06;

//Parameter für die NAG-Funktion d01ajc
double ug = 0.0;// untere Grenze
double og = 2*3.14159;// obere Grenze
double epsabs = 0.0;// absoulte accuracy
double epsrel = 0.001;// relative
Integer max_num_subint = 500; // maximale Anzahl der Subintervalle
double result;// Ergebnis
double abserr;
Nag_QuadProgress qp;
NagError fail;
fail.code = NE_NOERROR;

//integrieren der Funktion integrand
d01ajc (integrand, ug, og, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &fail);

// Berechnen von F
F = k * a * b * result;

// End of editable part
}


And this is my problem: The function integrand needs the value of h, which is a parameter of _nlsfKraftPM. I think that I can't change the number of parameters of integrand because it is called by the nag function d01ajc. So I don't know how to reach h in integrand. I also tried to write the value of h in a variable that is defined outside of the functions and acces this variable in integrand. This resulted in a runtime error.

Do you have any ideas what I could do to solve this probelm?
Is there another way to implement this fit-function?

Thank you very much for your help
Michael Becker
2   L A T E S T    R E P L I E S    (Newest First)
michaelbecker Posted - 06/02/2008 : 07:28:45 AM
Hi Fisher,

this did not work. If I remember right, the compiler said that I'm not allowed to use static variables in a precompiled header.
But I found another solution for my problem: I implemented the whole function F(h) in a c dll which is called directly by nonlinear fitting tool (so I don't need OrginC anymore).

Michael
fisher_zhang Posted - 06/02/2008 : 04:45:29 AM
Hi, michaelbecker


Have you tried using a global variable "static double h;"


Fisher

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