Hi I have some data And I want to fit a polinom these data Firstly I think it should be : ax^2 +bx+c and than x+x1=-b/a ;x*x1=c/a And I wrote this code:
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
void createfunction(double x,double x1)
{
int a,b,c;
double x2 = 1.0;
a=1;
b=(-a)*(x+x1);
c=a*(x*x1);
// int denklem=a*x2*x2+b*x2+c;
cout<<a<<"x^2+"<<b<<"x+"<<c<<endl;
// cout<<denklem;
//derive(a)
}
int main(int argc, char** argv) {
createfunction(100,101);
return 0;
}
It is wirking but I can understand that This method completely wrong :(after reading these http://mathbitsnotebook.com/Algebra1/StatisticsReg/ST2FittingFunctions.html https://en.wikipedia.org/wiki/Polynomial_regression
But I dont know how I can write this code in c Can you help me Thank your advance
Hmm this is a least square problem and there is an example in here : http://www.bragitoff.com/2015/09/c-program-for-polynomial-fit-least-squares/