Curve Fitting in C
==============
(exponent,Hyperbola,Straight line or regression line)
Exponent
========
#include <stdio.h>
#include <math.h>
#include <conio.h>
#define size 10
void main ()
{
float a,b,av,d;
//double e = 2.7128128;
void reg (float,float);
clrscr ();
printf("\n\tFitting an Exponential Curve\n");
reg (av,a);
a = (float)exp(av);
//b = -a;
fflush(stdin);
getch();
}
void reg(float a0,float a1)
{
int n,i;
float xsum=0,ysum=0,xsqsum=0,xysum=0,denom;
float x[size],y[size];
printf("\n\nEnter the number of candidate values available(n): ");
scanf("%d",&n);
printf("\n\nEnter the available coordinate of the line:\n");
for (i=0;i<n;i++)
{
printf("\nPoint %2d x: ",i+1);
fflush(stdin);
scanf("%f",&x[i]);
printf("y: ");
fflush (stdin);
scanf("%f",&y[i]);
ysum += y[i];
xysum += x[i]*y[i];
xsqsum += x[i]*x[i];
}
printf("\n\t\tMethod of Linear Regression:\n");
printf("--------------------------------------------\n");
printf("\n\tINDEPENDENT DEPENDENT");
printf("\n\tvariable variable");
printf("\n--------------------------------------------\n");
for (i=0;i<n;i++)
printf("\n\t%7.4f %7.4f %7.4f %7.4f",x[i],y[i],x[i]*x[i],x[i]*y[i]);
printf("\nSUMs: %7.4f" " %7.4f" " %7.4f" " %7.4f",xsum,ysum,xsqsum,xysum);
printf("\n--------------------------------------------\n");
a1 = (((float)n+xysum)-(xsum+ysum))/denom;
return;
}
Hyperbola
=========
#include <stdio.h>
#include <conio.h>
#define max 10
#define EPS 0.000001
void main ()
{
int i,n;
float x[max],y[max],sa,sx=0.0,sxx=0.0,sdy=0.0,denom,a,b,sdxy=0.0;
clrscr ();
printf("\t\tHyperbola Regression\n");
printf("Enter total number of data values: ");
scanf("%d",&n);
printf("\nEnter x and y values:\n");
for (i=0;i<n;i++)
{
printf("x[%d]: ",i+1);
scanf("%f",&x[i]);
printf("y[%d]: ",i+1);
scanf("%f",&y[i]);
}
for(i=0;i<n;i++)
{
sx += x[i];
sxx += x[i]*x[i];
sdxy += x[i]/y[i];
sdy += 1/y[i];
}
denom = n*sxx - sx*sx;
if (fabs(denom) > EPS)
{
a = ((n*sdxy) - (sx*sdy))/denom;
b = ((sdy*sxx) - (sx*sdxy))/denom;
printf("\nHyperbola REgression Line y=1/a,bx,f=1/n,f=bx+a\n");
printf("a = %f\n",a);
printf("b = %f\n",b);
}
else
printf("No Solution");
getch ();
}
Straight line or regression line
=========================
#include <stdio.h>
#include <conio.h>
#define MAX 20
void main ()
{
float Sx=0,Sy=0,Sxy=0,Sx2=0;
float denom,a2,a1,x[MAX],y[MAX];
int i,n;
clrscr ();
printf("Enter total number of data: ");
scanf("%d",&n);
printf("Enter x and y one by one for %d times\n",n);
for (i=0;i<n;i++)
{
printf("\nx[%d]: ",i+1);
scanf("%f",&x[i]);
printf("y[%d]: ",i+1);
scanf("%f",&y[i]);
}
for (i=0;i<n;i++)
{
Sx = Sx + x[i];
Sx2 = Sx2 + x[i]*x[i];
Sy = Sy + y[i];
Sxy = Sxy + x[i]*y[i];
denom = n*Sx2 - Sx*Sx;
a2 = (n*Sxy - Sx*Sy)/denom;
a1 = (Sy*Sx2 - Sx*Sxy)/denom;
}
printf("\nRegression Coefficients are as under:\n");
printf("\nSlop of Regression line: %f\n",a2);
printf("\nIntercept for the line: %f",a1);
getch ();
}
2 comments:
http://17951501.at.webry.info/201301/article_34.html
http://sns.cam111.com/blogs/entry/including-their-target-audience
http://www.soberhood.org/node/125734
http://www.benches2swings.com/vocab/catpath/there-difference-way-we-use-normal-telephone-number-and-way-we-use-toll-free-number.ht
http://www.bloglog.com/blog/xmyshang6/126031/the-number-experiences
http://cinecloudfilms.com/index.php?do=/blog/92473/there-m-a-r-c-b-y-m-a-r-c-j-a-c-o-b-s-%E3%83%90-%E3%83%83-%E3%82%B0-is-presently-only-one-option-fo/
http://sns.cam111.com/blogs/entry/After-subscribing
http://www.moselbook.de/index.php?p=blogs/viewstory/144331
http://idioproject.com/social/index.php?do=/blog/57365/having-too-many-spyware-removers-or-running-on-your-system-actually-could-b/
http://developinglinks.com/index.php?do=/blog/133975/having-too-many-spyware-removers-or-running-on-your-system-actually-could-b/
http://archive.remdublin.com/blog/xmyshang/2013/01/27/jatimberlandsale
http://d.hatena.ne.jp/rrrtt/20130128/1359357923
http://sns.cam111.com/blogs/entry/emergence-of-new-market-players-and-innovations
http://nen360.nenonline.org/blog/itll-be-big-itll-be-tough
http://blog.qlep.com/blog.php/218220/718501
I like the valuable info you supply on your articles.
I will bookmark your blog and take a look at
once more right here frequently. I am quite sure I'll learn a lot of new stuff proper right here!
Good luck for the next!
Here is my webpage psn code generator
Post a Comment