Requirements: this is the data on the front end through echarts now I need to show out the shape of the article according to the previous data to determine the current state of the data points
Try: 1. Baidu before using least square method for fitting curve but feel slope does not return, don't know if there is something wrong in my understanding of the return value of the local
My function:
///& lt; Summary>
///using the least squares fitting binary multiple curve
///& lt;/summary>
///& lt; Param name="arrX & gt;" X coordinate of known points set & lt;/param>
///& lt; Param name="' arrY & gt;" The y coordinate of known points set & lt;/param>
///& lt; Param name="length" & gt; The number of known points & lt;/param>
///& lt; Param name="dimension" & gt; Maximum number of equation & lt;/param>
Private 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);
}
Private 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;
}
Private 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;
}
Private 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);
}
}
}//end for (j=0; J
For (I=n - 1; I & gt;=0; I -)
{
S=0;
For (j=I + 1; J & lt; n; J++)
{
S=s + Guass [I, j] * x [j];
}
[I]=x (Guass [I, n] -s)/Guass [, I].
}
return x;
}//the return value is the function of the coefficient of
CodePudding user response:
I think there's another solution: take a piece of data through the curve of peak and trough values to judge whether a single direction and then set up a band, filtering small fluctuations, do not know if this idea okCodePudding user response:
For example://gaussian matrix y=a0 + a1 + a2 * * x x x xThe calculated the
CodePudding user response: