/*------------------------------------------------------------------------------* * File Name: AccessFittingFunctionDirectly.c * * Creation: ER, 01/17/05 * * Purpose: Programming Example * * Copyright (c) OriginLab Corp.2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ #include ///////////////////////////////////////////////////////////////////////////////// // This example shows how to access built-in NLSF fitting functions directly // from OC to generate y values, without having to use the LabTalk NLSF object. // Note that this does not work for user-defined functions. // void access_fitting_function_directly() { // Create new worksheet Worksheet wks; wks.Create(); // Declare x, y datasets and check validity Dataset dsX(wks, 0); Dataset dsY(wks, 1); if( !dsX || !dsY ) return; // Fill x dataset with desired x values // Here we fill with values from 1.0 to 10.0 in steps of 0.1 dsX.Data(1.0, 10.0, 0.1); // Set the size of the y dataset to be same as the x dataset int iSize = dsX.GetSize(); dsY.SetSize(iSize); // We will now use the Gauss function to generate the y values // // There are two ways to do this: // Method 1: // Set up an array of parameters for the Gauss function // Gauss function has 4 parameters double dPar[4]; dPar[0] = 10; // y-offset dPar[1] = 5.5; // xc dPar[2] = 3; // w dPar[3] = 100; // A // Generate y values for(int ii = 0; ii < iSize; ii++) dsY[ii] = nlfGauss(dsX[ii], dPar, 4); // // Method 2: // Directly pass parameters as part of function call: // This time let us use the GaussMod function // Note that GaussMod has 5 parameters for(ii = 0; ii < iSize; ii++) dsY[ii] = nlfxGaussMod(dsX[ii], 5, 6.5, 3, 100, 5); // Note: // For either method, you just need to use the appropriate name // of the built-in fitting function: // nlfFunctionName or nlfxFunctionName // where FunctionName" is the name of the fitting function in // the FDF file, which typically is same as the name of the // FDF disk file. } /////////////////////////////////////////////////////////////////////////////////