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
 linear fitt a part of a curve in the active graph?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

liujibao

China
Posts

Posted - 12/24/2003 :  8:49:54 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
How to linear fit a part of a curve in the active graph, and draw it in the graph?

liujibao

China
Posts

Posted - 12/24/2003 :  9:00:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I am sorry for create a same topic, please the admin delete it, Thanks!
Go to Top of Page

liujibao

China
Posts

Posted - 12/24/2003 :  11:12:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
will you help me?
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 12/25/2003 :  10:53:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Use the Data Selector to select the range of data, then do the linear fit. Once the Data Selector is used to select a range of the curve, then all subsequent analysis operations will be performed only between the two data markers.

CP


Go to Top of Page

liujibao

China
Posts

Posted - 12/26/2003 :  03:37:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
My means is how to realize it by origin c code?
Are there such origin c functions, such as linear fitting function?
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 12/26/2003 :  11:12:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
LabTalk's curve fitter (NLSF) is accessible from OC using LabTalk.nlsf.property and LabTalk.nlsf.method.

Mike Buess
Origin WebRing Member
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 12/26/2003 :  1:46:51 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Until we move all these Origin analysis functions into Origin C, LabTalk would still be needed. I can put together a good wrapper OC function when I have some time and post it here. Basically, what is needed is a function similar to fitpoly in internal.c

CP


Go to Top of Page

cpyang

USA
1406 Posts

Posted - 12/26/2003 :  4:37:16 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The following code demonstrate the usage of Curve copy constructor to copy a sub range of the Active Dataset, thus avoiding the range selection complication that might arise with SetLowerBound etc calls. Please note that I have merely used the existing fitpoly function, but a more extensive linear fit function with all the needed statistics results will be needed later to improve this. We are planning to provide much of these LLOC (low level OC) functions in future releases.



/**
linear fit to active data between specified range by row numbers, a red fit curve is added to the graph
Parameters:
nLower = lower index to start from or -1 to start from the lower bound.
nUpper = upper index to end at, or -1 to end at the upper bound.
nFitXRange = -1 to fill entire X range, 0 to be from x1 to x2, >0 percent extra outside x1 x2
*/
void fitlr(int nLower = -1, int nUpper = -1, int nFitXRange = 0)
{
string strCuvName = Project.ActiveCurveBase().GetName();
if(strCuvName.IsEmpty())
return;
GraphLayer glyr = Project.ActiveLayer();
if(glyr == NULL)
return;// we only will fit a graph

int nNumMissingInCopy, nSrcOffset;
// create a temp copy of Active curve to ensure data type is double and original range is not modified
Curve cc(Project.ActiveCurveBase(), nNumMissingInCopy, nSrcOffset,
CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT | CURVECOPY_SCAN_OVER_MISSING_FROM_RIGHT | CURVECOPY_SKIP_MISSING_INSIDE,
nLower, nUpper);

double coeff[2];
fitpoly(cc, 1, coeff); // using built-in simple fitting function, sorry, no stats report

// generate fit curve
double x1, x2;

if(nFitXRange < 0) // span entire x axis
{
x1 = glyr.X.From;
x2 = glyr.X.To;
}
else // use data x range, with possible wider X range
{
x1 = Curve_x(&cc, 0);
x2 = Curve_x(&cc, cc.GetUpperIndex());
double dx = (x2-x1) * nFitXRange/100.0;
x1 -= dx;
x2 += dx;
}
Worksheet wksFit;
wksFit.Create(NULL, CREATE_HIDDEN);
wksFit.SetSize(-1,0);// empty all cols
wksFit.AddCol("FitX");
wksFit.AddCol("FitY");
wksFit.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X);
wksFit.Columns(1).SetType(OKDATAOBJ_DESIGNATION_Y);
Dataset fitx(wksFit, 0);
Dataset fity(wksFit, 1);
int nFitPts = 20;// generate fit curve of 20 pts
fitx.SetSize(nFitPts);
fity.SetSize(nFitPts);
vector vData;
vData.Data(0,nFitPts-1); // Generate 0, 1,2,... nFitPts
fitx = x1 + vData * (x2-x1) / (nFitPts - 1);
fity = coeff[0] + coeff[1] * fitx;
Curve cfit(wksFit, 0, 1);
add_curve_to_graph_layer(cfit, glyr, 1, false, IDM_PLOT_LINE);
}





CP

Edited by - cpyang on 12/26/2003 4:42:18 PM
Go to Top of Page

liujibao

China
Posts

Posted - 12/27/2003 :  02:10:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much!!!
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