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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 linear fitt a part of a curve in the active graph?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
liujibao Posted - 12/24/2003 : 8:49:54 PM
How to linear fit a part of a curve in the active graph, and draw it in the graph?
8   L A T E S T    R E P L I E S    (Newest First)
liujibao Posted - 12/27/2003 : 02:10:53 AM
Thank you very much!!!
cpyang Posted - 12/26/2003 : 4:37:16 PM
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
cpyang Posted - 12/26/2003 : 1:46:51 PM
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


Mike Buess Posted - 12/26/2003 : 11:12:35 AM
LabTalk's curve fitter (NLSF) is accessible from OC using LabTalk.nlsf.property and LabTalk.nlsf.method.

Mike Buess
Origin WebRing Member
liujibao Posted - 12/26/2003 : 03:37:32 AM
My means is how to realize it by origin c code?
Are there such origin c functions, such as linear fitting function?
cpyang Posted - 12/25/2003 : 10:53:40 AM
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


liujibao Posted - 12/24/2003 : 11:12:45 PM
will you help me?
liujibao Posted - 12/24/2003 : 9:00:42 PM
I am sorry for create a same topic, please the admin delete it, Thanks!

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000