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
 fit to a function with origin c and nag
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

michaelbecker

Germany
Posts

Posted - 05/20/2008 :  07:33:17 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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 fr 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

fisher_zhang

China
Posts

Posted - 06/02/2008 :  04:45:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, michaelbecker


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


Fisher
Go to Top of Page

michaelbecker

Germany
Posts

Posted - 06/02/2008 :  07:28:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
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