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
 how to write a linear fitting function ?

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
70WorkRoom Posted - 07/22/2007 : 01:25:32 AM
Origin Version (Select Help-->About Origin): Origin v7.5
Operating System:Windows 2000

when i write a test linear fit arithmetic to make a line:Y = kX + b.
but the result is always different from the origin linear fit.may be i miss something in my programe,can someone help me?Thanks very much.

My Code is as follow:
 
#include <stdio.h>

#define MAXNODE 24

double sum1(double a[],int n)
{
double y=0; int i;
for(i=0;i<n;i++)
y+=a[i];
return(y);
}
double sum2(double a[],int n)
{
double y=0; int i;
for(i=0;i<n;i++)
y+=a[i]*a[i];
return(y);
}
double sum3(double a[], double b[],int n)
{
double y=0; int i;
for(i=0;i<n;i++)
y+=a[i]*b[i];
return(y);
}
int main()
{
double a,b;
int N = 24;

double x[24] = {0.00186,
0.00185,
0.00184,
0.00184,
0.00183,
0.00182,
0.00181,
0.0018,
0.00179,
0.00179,
0.00178,
0.00177,
0.00176,
0.00176,
0.00175,
0.00174,
0.00173,
0.00172,
0.00172,
0.00171,
0.0017,
0.0017,
0.00169,
0.00168};

double y[24] = {-13.71611,
-13.6033,
-13.58863,
-13.48522,
-13.47886,
-13.39108,
-13.33716,
-13.27675,
-13.23764,
-13.16014,
-13.0996,
-13.05467,
-12.97989,
-12.95996,
-12.92921,
-12.84708,
-12.83526,
-12.77366,
-12.68855,
-12.66473,
-12.65777,
-12.60471,
-12.5354,
-12.45963};

a=(N*sum3(x,y,N)-sum1(x,N)*sum1(y,N))/(N*sum2(x,N)-sum1(x,N)*sum1(x,N));
b=(sum1(y,N)*sum2(x,N)-sum1(x,N)*sum3(x,y,N))/(N*sum2(x,N)-sum1(x,N)*sum1(x,N));

printf("Result is:\n y=%f x + %f\n",a,b);
return 0;
}



my result is:y=-6694.250717 x + -1.219209

And the origin result log is:
[2007-7-22 12:19 "/Graph1" (2454303)]
Linear Regression for Data3_B:
Y = A + B * X

Parameter Value Error
------------------------------------------------------------
A -1.27315 0.1525
B -6662.66738 86.18488
------------------------------------------------------------

R SD N P
------------------------------------------------------------
-0.99816 0.02291 24 <0.0001


Edited by - 70WorkRoom on 07/22/2007 01:31:33 AM
2   L A T E S T    R E P L I E S    (Newest First)
70WorkRoom Posted - 07/30/2007 : 05:16:13 AM
thank you very much.
Mike Buess Posted - 07/22/2007 : 10:11:58 AM
I'm not sure what you did but after copying your data to worksheet both the Analysis> Fit Linear and Tools>Linear Fit commands give me the Result Log report shown at the bottom. Note that slope and intercept are same as those obtained from your formula. This is how Origin does its linear regression...
http://www.originlab.com/www/helponline/origin/Linear_Regression.htm



Mike Buess
Origin WebRing Member

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