Author |
Topic |
|
DB-L
France
4 Posts |
Posted - 02/06/2015 : 06:28:03 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): 9.1 Operating System: windows vista on VMware os X
Hello, for fitting data, I need to find the root of a polynomial (vx). For this I include Newton-Rhapson method in the fit. I determine a function vfx and its derivate vdf. after fews iterations I obtain the value of vx. This works well with "double" but with my data "vector" . I can't compile, the message : "error: incompatibles variables" appears... My code is pasted just below. Is someone could help me please! Best regards.
#pragma numlittype(push, TRUE) #pragma numlittype(push, TRUE) #pragma warning(error : 15618) #include <origin.h> #include <math.h> #include <stdio.h>
// Add your special include files here. // For example, if you want to fit with functions from the NAG library, // add the header file for the NAG functions here.
#include <ONLSF.H> #include <OC_nag.h>
// Add code here for other Origin C functions that you want to define in this file, // and access in your fitting function.
// You can access C functions defined in other files, if those files are loaded and compiled // in your workspace, and the functions have been prototyped in a header file that you have // included above.
// You can access NLSF object methods and properties directly in your function code.
// You should follow C-language syntax in defining your function. // For instance, if your parameter name is P1, you cannot use p1 in your function code. // When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5 // Use 0.5 or 1/2.0 to get the correct value.
// For more information and examples, please refer to the "User-Defined Fitting Function" // section of the Origin Help file.
//---------------------------------------------------------- // void _nlsfmultiSites( // Fit Parameter(s): double n, double L, double K12, double H12, double H1, double K1, double H2, double K2, // Independent Variable(s): double x, // Dependent Variable(s): double& y) { // Beginning of editable part Worksheet wks = Project.ActiveLayer(); NLFitContext *pCtxt = Project.GetNLFitContext(); if ( pCtxt ) { static vector vX, vY; static int nSize; BOOL bIsNewParamValues = pCtxt->IsNewParamValues(); if ( bIsNewParamValues ) { Dataset dsMt( wks, 2 ), dsXMt( wks, 0 ); int nn = dsXMt.GetSize(); vector vTheta( nn ), vC12, vC1, vC2; vector vdH1dx, vdH2dx, vdHdx, vdrdx; vC12 = n*K12*dsMt; vC1 = n*K1*dsMt; vC2 = n*n*K2*dsMt*dsMt; vector vx, vx1, vx2, vx3, vfx, vdf, vdx, vrtn; int J; vx1 = 0; vx2 = L*dsXMt/n; vx3 = dsXMt/1000000000; vrtn = 0.5*(vx1 + vx2); for (J=1; J<=100; J++) { vfx = vrtn^2; // (-(1+vC1*vrtn+vC2*vrtn^2)+sqrt(8*vC12^2*vrtn+(1+vC1*vrtn+vC2*vrtn^2)^2))*(1-vC1*vrtn-3*vC2*vrtn^2)-((4*vC12^2*vrtn)*(1+2*vrtn-(2*L*dsXMt/n))); // function vdf = 2*vrtn; //((-6*vC2*vrtn-vC1)*(sqrt((vC2*vrtn^2+vC1*vrtn+1)+8*vC12^2*vrtn)-vC2*vrtn^2-vC1*vrtn-1) + (-3*vC2*vrtn^2-vC1*vrtn+1)*((2*(2*vC2*vrtn+vC1)*(vC2*vrtn^2+vC1*vrtn+1)+8*vC12^2)/(2*sqrt((vC2*vrtn^2+vC1*vrtn+1)^2+8*vC12^2*vrtn))-2*vC2*vrtn-vC1) - 4*vC12^2*(2*vrtn-(2*L*dsXMt/n)-8*vC12^2*vrtn) ; // derivate of function vdx = - vfx/vdf; vrtn += vdx; if ((vdx*vdx) < vx3) { vx = vrtn; // maybe an exit(0)? } } vdrdx = -(-vC1-2*vC2*vx+(((1+vC1*vx+vC2*vx^2)*(vC1+2*vC2*vx)+4*vC12^2)/sqrt((1+vC1*vx+vC2*vx^2)^2+8*vC12*vC12*vx)))*((1/vx)-vC1-3*vC2*vx)*(n/(8*vC12*vC12*L))+(-(1+vC1*vx+vC2*vx^2)+sqrt((1+vC1*vx+vC2*vx^2)^2+8*vC12*vC12*vx))*((1/(vx^2)+3*vC2))*(n/(8*vC12^2*L))+(n/L); vdH1dx = (n/(4*vC12^2))*(-vC1-2*vC2*vx+(((1+vC1*vx+vC2*vx^2)*(vC1+2*vC2*vx)+4*vC12^2)/sqrt((1+vC1*vx+vC2*vx^2)^2+8*vC12^2*vx)))*(0,5*H12*((-1/vx)-vC1-vC2*vx)+vC1*H1+vC2*H2*vx); vdH2dx = (n/(4*vC12^2))*(-(1+vC1*vx+vC2*vx^2)+ sqrt((1+vC1*vx+vC2*vx^2)^2+8*vC12^2*vx))*(0,5*H12*((1/(vx^2))-vC2)+H2*vC2); vdHdx = vdH1dx + vdH2dx; vY = vdHdx/vdrdx; } ocmath_interpolate( &x, &y, 1, vX, vY, nSize ); } // End of editable part } |
|
jasonzhao
China
262 Posts |
Posted - 02/09/2015 : 03:22:25 AM
|
Hello,
Would you please share your data, fdf file, OPJ file, and fitting formula with us by mail <tech@originlab.com>?
Best regards! Jason OriginLab Technical Service |
Edited by - jasonzhao on 02/09/2015 03:23:28 AM |
|
|
|
Topic |
|
|
|