Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
271a7bd3
Commit
271a7bd3
authored
Apr 16, 2020
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev6.0' of
http://private.flyautomation.net:82/panruising/thick_public
into dev6.0
parents
975f48ba
78c4f7f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
8 deletions
+105
-8
MyMath.cs
Project.FLY.Misc/MISC/MyMath.cs
+105
-8
No files found.
Project.FLY.Misc/MISC/MyMath.cs
View file @
271a7bd3
...
...
@@ -72,7 +72,10 @@ namespace Misc
{
return
Max
(
buf
,
0
,
buf
.
Count
()
-
1
);
}
public
static
double
Max
(
IEnumerable
<
double
>
buf
)
{
return
Max
(
buf
,
0
,
buf
.
Count
()
-
1
);
}
/// <summary>
/// 排除 NULL_VALUE, 求最大值
/// </summary>
...
...
@@ -95,6 +98,21 @@ namespace Misc
}
return
max
;
}
public
static
double
Max
(
IEnumerable
<
double
>
buf
,
int
first
,
int
last
)
{
double
max
=
double
.
NaN
;
for
(
int
i
=
first
;
i
<=
last
;
i
++)
{
if
(!
double
.
IsNaN
(
buf
.
ElementAt
(
i
)))
{
if
(
max
==
double
.
NaN
)
max
=
buf
.
ElementAt
(
i
);
else
if
(
max
<
buf
.
ElementAt
(
i
))
max
=
buf
.
ElementAt
(
i
);
}
}
return
max
;
}
/// <summary>
/// 排除 NULL_VALUE, 求最小值
/// </summary>
...
...
@@ -104,13 +122,16 @@ namespace Misc
{
return
Min
(
buf
,
0
,
buf
.
Count
()
-
1
);
}
/// <summary>
/// 排除 NULL_VALUE, 求最小值
/// </summary>
/// <param name="buf"></param>
/// <param name="first">开始序号</param>
/// <param name="last">结束序号</param>
/// <returns></returns>
public
static
double
Min
(
IEnumerable
<
double
>
buf
)
{
return
Min
(
buf
,
0
,
buf
.
Count
()
-
1
);
}
/// <summary>
/// 排除 NULL_VALUE, 求最小值
/// </summary>
/// <param name="buf"></param>
/// <param name="first">开始序号</param>
/// <param name="last">结束序号</param>
/// <returns></returns>
public
static
int
Min
(
IEnumerable
<
int
>
buf
,
int
first
,
int
last
)
{
int
min
=
MyBase
.
NULL_VALUE
;
...
...
@@ -127,6 +148,22 @@ namespace Misc
}
return
min
;
}
public
static
double
Min
(
IEnumerable
<
double
>
buf
,
int
first
,
int
last
)
{
double
min
=
double
.
NaN
;
for
(
int
i
=
first
;
i
<=
last
;
i
++)
{
if
(!
double
.
IsNaN
(
buf
.
ElementAt
(
i
)))
{
if
(
min
==
double
.
NaN
)
min
=
buf
.
ElementAt
(
i
);
else
if
(
min
>
buf
.
ElementAt
(
i
))
min
=
buf
.
ElementAt
(
i
);
}
}
return
min
;
}
/// <summary>
/// 排除 NULL_VALUE, 求平均值
/// </summary>
...
...
@@ -136,6 +173,10 @@ namespace Misc
{
return
Avg
(
buf
,
0
,
buf
.
Count
()
-
1
);
}
public
static
double
Avg
(
IEnumerable
<
double
>
buf
)
{
return
Avg
(
buf
,
0
,
buf
.
Count
()
-
1
);
}
/// <summary>
/// 排除 NULL_VALUE, 求平均值
/// </summary>
...
...
@@ -164,7 +205,27 @@ namespace Misc
else
return
MyBase
.
NULL_VALUE
;
}
public
static
double
Avg
(
IEnumerable
<
double
>
buf
,
int
first
,
int
last
)
{
double
sum
=
0
;
int
cnt
=
0
;
for
(
int
i
=
first
;
i
<=
last
;
i
++)
{
if
((
i
>=
0
)
&&
(
i
<
buf
.
Count
()))
{
if
(!
double
.
IsNaN
(
buf
.
ElementAt
(
i
)))
{
sum
+=
buf
.
ElementAt
(
i
);
cnt
++;
}
}
}
if
(
cnt
!=
0
)
return
sum
/
cnt
;
else
return
double
.
NaN
;
}
/// <summary>
/// 排除 NULL_VALUE, 求平均值, 无方向 last < first 也可以
/// </summary>
...
...
@@ -397,6 +458,42 @@ namespace Misc
}
}
public
static
void
Linest
(
IEnumerable
<
double
>
y
,
IEnumerable
<
double
>
x
,
out
double
a
,
out
double
b
)
{
if
(
y
.
Count
()
!=
x
.
Count
())
{
throw
new
Exception
(
"Linest() 参数异常 (y.Length="
+
y
.
Count
()
+
") != (x.Length="
+
x
.
Count
()
+
")"
);
}
double
sum_x
=
0
;
double
sum_y
=
0
;
double
sum_x2
=
0
;
double
sum_xy
=
0
;
int
n
=
y
.
Count
();
int
cnt
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
if
(!
double
.
IsNaN
(
x
.
ElementAt
(
i
))
&&
!
double
.
IsNaN
(
y
.
ElementAt
(
i
)))
{
sum_xy
+=
y
.
ElementAt
(
i
)
*
x
.
ElementAt
(
i
);
sum_x2
+=
x
.
ElementAt
(
i
)
*
x
.
ElementAt
(
i
);
sum_x
+=
x
.
ElementAt
(
i
);
sum_y
+=
y
.
ElementAt
(
i
);
cnt
++;
}
}
if
(
cnt
>
1
)
{
a
=
(
n
*
sum_xy
-
sum_x
*
sum_y
)
/
(
n
*
sum_x2
-
sum_x
*
sum_x
);
b
=
sum_y
/
n
-
a
*
sum_x
/
n
;
}
else
{
a
=
1
;
b
=
0
;
}
}
/// <summary>
/// 对环形数据 分区移位
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment