Code:
#include "asuro.h"
int main(void)
{
// y wird durch indiv. Messwerte ersetzt
int y[] = {1000, 1015, 1031, 1047, 1062, 1079, 1095, 1111, 1125, 1142,
1157, 1173, 1190, 1206, 1222, 1238, 1258, 1274, 1290, 1307,
1322, 1339, 1355, 1369, 1384, 1401, 1417, 1433, 1449, 1466,
1480, 1498, 1525, 1541, 1557, 1574, 1589, 1606, 1621, 1637,
1653, 1669, 1685, 1699, 1716, 1734, 1749, 1764, 1785, 1801,
1817, 1833, 1850, 1867, 1881, 1898, 1912, 1930, 1945, 1960,
1975, 1994, 2010, 2026},
A[2][64] = {{
6106, 5962, 5817, 5673, 5529, 5385, 5240, 5096, 4952, 4808,
4663, 4519, 4375, 4231, 4087, 3942, 3798, 3654, 3510, 3365,
3221, 3077, 2933, 2788, 2644, 2500, 2356, 2212, 2067, 1923,
1779, 1635, 1490, 1346, 1202, 1058, 913, 769, 625, 481,
337, 192, 48, -96, -240, -385, -529, -673, -817, -962,
-1106, -1250, -1394, -1538, -1683, -1827, -1971, -2115, -2260, -2404,
-2548, -2692, -2837, -2981},
{
-144, -140, -135, -130, -126, -121, -117, -112, -108, -103,
-98, -94, -89, -85, -80, -76, -71, -66, -62, -57,
-53, -48, -43, -39, -34, -30, -25, -21, -16, -11,
-7, -2, 2, 7, 11, 16, 21, 25, 30, 34,
39, 43, 48, 53, 57, 62, 66, 71, 76, 80,
85, 89, 94, 98, 103, 108, 112, 117, 121, 126,
130, 135, 140, 144}};
int i;
float p1,p2,fkt=1.e5;
p1 = p2 = 0;
Init();
SerWrite("\n\rlin.Regression:\n\r",19);
for (i = 0; i < 64; i++) {
p1 += (float)A[0][i]*(float)y[i];
p2 += (float)A[1][i]*(float)y[i];
}
p1 /= fkt;
SerWrite("bias: 0.",8);
Msleep(100);
PrintInt(p1);
SerWrite("\n\r",2);
p2 = 1000*fkt/p2;
SerWrite("slope: ",7);
Msleep(100);
PrintInt(p2);
SerWrite(".",2);
PrintInt((int)((p2-(int)p2)*10.0+0.5));
SerWrite("\n\r",2);
while (1);
return 0;
}
Das Prg spuckt zwei Werte aus: bias b (bei mir 0.995) und slope s (die Steigung der Gerade, bei mir 61.0).
Lesezeichen