Home > Net >  Data fitting and derivative curve inflection point
Data fitting and derivative curve inflection point

Time:10-04

Data fitting curve and the second derivative to zero, and inflection point
Why can't upload files
?I found a fitting program and inflection point how to set the two together?
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent ();
}
Public struct point//public struct PersonStruct
{
Public double x;
Public double y;
};


//point [] p;//PersonStruct p1, p2,//like the class, but can not new int [] arr1;

Point p=new point [] [200].
Positive linear equation//
Double fun (point p1, point p2, p3 is point)
{

Double s;
S=(p2) X-ray (p1) x) * (p3) y - p1) y) + (p1) y - p2) y) * (p3) X-ray (p1) x);
Return s;
}


//to get test point inflection point
Void getPoint ()
{
Double I;
int j=0;
For (I=0; I & lt; 7. I +=0.035)
{
P [j]. Journal of x=I;
P [j]. J y=math.h Sin (I);//this is a sin if other formula how to do??????

////function exactly????? How much is coefficient, coefficient of how many???
j++;
}


}
//the first step: least squares curve fitting matlab polyfit
//step 2: the second derivative to zero, and discrete point matlab diff
Private void button1_Click (object sender, EventArgs e)
{
//double [] y={110, 160, 190, 235, 264, 274, 295};
//double [] x={10, 50, 130, 188, 255, 316, 487};
Double [] x={60, 120, 180, 240, 300, 360, 420};
//double [] y={30, 31, 32, 33 and 34, 33.5, 34.5};
Double [] y={- - 30, 31, - 32-33-33.5, - 34, 34.5};
Double [] f=ecf. MultiLine (x, y, 7, 4);//fitting function, the return value is the function of the coefficients of the fitting of the code in the ecf. Cs
//such as: y=a0 + a1 * x the return value is a0 a1
//such as: y=a0 + a1 + a2 * * x x x x the return value is a0 a1 a2
//ecf. The cs kao to new project folder, and then used to add items to be added to the existing projects, attention to modify the ecf. Cs namespace
//function exactly????? How much is coefficient, coefficient of how many???
Bitmap b1=new Bitmap (500, 300);
Graphics G2=Graphics. FromImage (b1);
SolidBrush mysbrush1=new SolidBrush (Color. DarkOrchid);
Pen p1=new Pen (mysbrush1);
P1. Color=Color. Green;
P1. Width=3;

int i;
For (I=0; I & lt; Y.L ength - 1; I++)
G2. DrawLine (p1, new PointF (x [I] (float), 300 - (float) y [I]),
New PointF ((float) x [I + 1), 300 - (float) y/I + 1));
P1. Color=Color. Red;
For (I=0; I & lt; (int) x.M ax (); I++)
{
Float y1=(float) (f [0] + [1] * I f + f [2] * math.h Pow (I, 2) + f [3] * math.h Pow (I, 3) + f [4] * math.h Pow (I, 4));
Float y2=(float) (f [0] + [1] f * (I + 1) + f [2] * math.h Pow (I + 1, 2) + f [3] * math.h Pow (I + 1, 3) + f [4] * math.h Pow (I + 1, 4));
//G2. DrawLine (p1, new PointF ((float), 300 - y1),
//new PointF ((float) (I + 1), 300 - y2));
G2. DrawLine (p1, new PointF ((float), I (0 to 7 * y1)),
New PointF ((float) (I + 1), (0 to 7 * y2)));

}
G2. The Save ();
PictureBox1. Image=b1;
Int j;


GetPoint ();
Double s1, s2;
For (I=3; I & lt; 199; I++)
{
S1=fun (p/I - 2), p (I - 1], [I] p);
S2=fun (p/I - 1], [I] p, p/I + 1);


If (s1 * s2 & lt; 0)
{
Lf lf//printf (" % % \ n ", p [I] x and p [I] y);
Label1. Text=p [I] x.T oString ();
Label2. Text=p [I] y.T oString ();
}


}
}
}
Public static double [] MultiLine (double [] arrX, double [] 'arrY, int length, int dimension)//binary multiple linear equation fitting curve
{
Int n=dimension + 1;//dimension equation needs dimension coefficient of + 1
Double [and] Guass=new double [n, n + 1); For example://gaussian matrix y=a0 + a1 + a2 * * x x x x
For (int I=0; I & lt; n; I++)
{
Int j;
For (j=0; J & lt; n; J++)
{
Guass [I, j]=SumArr (arrX, j + I, length);
}
Guass [I, j]=SumArr (arrX, I, 'arrY, 1, length);
}
Return ComputGauss (Guass, n);

}

Public static double SumArr (double [] arr, int n, int length)/n/o array elements and
{
Double s=0;
For (int I=0; I & lt; Length; I++)
{
If (arr [I]!=0 | | n!=0)
S=s + math.h Pow (arr [I], n);
The else
S=s + 1;
}
Return s;
}
Public static double SumArr (double [] arr1, int n1, double [] arr2, int n2, int length)
{
Double s=0;
For (int I=0; I & lt; Length; I++)
{
If ((arr1 [I]!=0 | | n1!=0) & amp; & (arr2 [I]!=0 | | n2!=0))
S=s + math.h Pow (arr1 [I], n1) * math.h Pow (arr2 [I], n2);
The else
S=s + 1;
}
Return s;

}

Public static double [] ComputGauss (double [and] Guass, int n)
{
Int I, j;
Int k, m;
Double temp.
Double Max;
Double s;
Double x=new double [] [n].

For (I=0; I & lt; n; I++) x [I]=0.0;//initialize


For (j=0; J & lt; n; J++)
{
Max=0;

K=j;
For (I=j; I & lt; n; I++)
{
If (Math. Abs (Guass [I, j]) & gt; Max)
{
Max=Guass (I, j),
K=I;
}
}



If (k!=j)
{
For (m=j; M & lt; N + 1; M++)
{
Temp=Guass [j, m];
Guass [j, m]=Guass (k, m),
Guass [k, m]=temp;

}
}

If (0==Max)
{
//"the linear equations for singular linear equations"

return x;
}


For (I=j + 1; I & lt; n; I++)
{

S=Guass (I, j),
For (m=j; M & lt; N + 1; M++)
{
Guass [I, m]=Guass [I, m] - Guass [j, m] * s/(Guass [j] j);

}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C #
  • Related