Author |
Topic  |
|
whm
China
1 Posts |
Posted - 05/19/2016 : 11:11:34 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): Operating System:
Hello,
I try to fit an ordinary differential equation(ODE) using the NAG solver d02ejc which is a function for integrating stiff systems.
here's my code, just following the example and manual:
#pragma numlittype(push, TRUE) #pragma warning(error : 15618) #include <origin.h> #include <oc_Nag8.h> #include <ONLSF.H> #include <NAG\nagd02.h>
struct user // parameter in the ODE { double k1; double xend,h; int k; };
static void NAG_CALL fcn(int neq, double x, double y[], double f[], Nag_User *comm) { neq;// Number of ordinary differential equations x; //Independent variable y; //Dependent variables f; //First derivative struct user *s = (struct user *)(comm->p); double k1; k1 = s->k1; f[0] = -k1*y[0]; } static void NAG_CALL pederv(int neq, double x, double y[], double pw[], Nag_User *comm) { neq; //Number of ordinary differential equations x; //Independent variable y; //Dependent variables pw; //Jacobian of the system struct user *s = (struct user *)(comm->p); double k1; k1 = s->k1; PW(1,1) = -k1; }
//Use BDF to solve ODE static bool nag_ode_fit( const double k1, const double y0, const double tstart, const double tend, const int nout, vector &vP ) { //nout: Number of points to output tend; if( nout < 2 ) return false; vP.SetSize( nout ); vP[0] = y0; int neq = 1; //Number of ordinary differential equations int j; double x, y[1]; double tol; double tinc, twant; Nag_User comm; struct user s; x=0.0; y[0] = y0; tinc= (tend-tstart)/(nout-1); tol=1e-03; for (j=1; j<nout; j++) { s.k1 = k1; s.k=nout; s.xend = tstart+j*tinc; s.h=(s.xend - x)/(double)(s.k + 1); comm.p = (Pointer)&s; d02ejc(neq, fcn, pederv, &x, y, s.xend, tol, Nag_Relative, NULLFN, NULLFN, &comm, NAGERR_DEFAULT); vP[j] = y[0]; } return true; }
//---------------------------------------------------------- // void _nlsfBDF( // Fit Parameter(s): double k1, double OH, // Independent Variable(s): double x, // Dependent Variable(s): double& y) { // Beginning of editable part NLFitContext *pCtxt = Project.GetNLFitContext(); if ( pCtxt ) { static vector vX, vY; static int nSize; BOOL bIsNewParamValues = pCtxt->IsNewParamValues(); // If parameters were updated, we will recalculate the ODE result. if ( bIsNewParamValues ) { //Initial and final values of the independent variable double tstart = 0.0, tend = 0.0015, tinc; int nout = 1001; //Number of points tinc = (tend-tstart)/(nout-1); vX.Data( tstart, tend, tinc ); nSize = vX.GetSize(); if( !nag_ode_fit( k1, OH, tstart, tend, nout, vY) ) return; } //Interpolate y from fitting data's x on the ODE result. ocmath_interpolate( &x, &y, 1, vX, vY, nSize ); } // End of editable part }
When compiling, I always got: Error, invalid explicit cast, for the line "d02ejc(neq, fcn, pederv, &x, y, s.xend, tol, Nag_Relative, NULLFN, NULLFN, &comm, NAGERR_DEFAULT)" namely when the solver is called.
My first thought is that there is something unsupported in the function of d02ejc, which I couldn't see. However, if I'm wrong, and/or if there is a way to do what my piece of code is supposed to do, I would appreciate you tell me.
p.s. I have tried before using a more basic solver, d02pcc, and succeeded. However, I want to try d02ejc to solve a more stiff system.
|
|
jasonzhao
China
262 Posts |
Posted - 05/20/2016 : 03:25:18 AM
|
Hello,
You can send your OPJ file for us to make a further test by mail: tech@originlab.com.
Best regards! Jason OriginLab Technical Service |
Edited by - jasonzhao on 05/20/2016 10:37:40 PM |
 |
|
mablitz
United Kingdom
2 Posts |
|
mablitz
United Kingdom
2 Posts |
Posted - 05/20/2016 : 5:20:08 PM
|
In order to do data analysis the ODE needs to be called from within Origin C. How do you call the ODE solver App from Origin C? The code for this App appears to be hidden so it cannot be written into the Origin C code.
Mark
quote: Originally posted by mablitz
quote: Originally posted by jasonzhao
Hello,
You can try to use the ODE Solver App in Origin 2016 to solve your problem http://www.originlab.com/fileExchange/details.aspx?fid=222
Best regards! Jason OriginLab Technical Service
mark blitz
mark blitz |
 |
|
|
Topic  |
|
|
|