用C语言实现了一下3.3中的对率回归问题,C语言求逆矩阵是个很麻烦的事情,这里参考了一些网上的博客,偷了懒。
#include<stdio.h>
#include<string.h>
#include<math.h>
typedef struct parameter{
double w[10];
int w_lenght;
double b;
}parameter;
typedef struct input{
double x[10];
int x_lenght;
double const_num;
}input;
double mix[3][3];
void matrix_a(double temp[3][3])
{
int k, k2;
for (k = 0; k < 3; k++){
for(k2 = 0; k2 < 3; k2++){
mix[k][k2]+=temp[k][k2];
}
}
}
int matrix_inv(int ndimen)
{
double tmp, tmp2, b_tmp[20], c_tmp[20];
int k, k1, k2, k3, j, i, j2, i2, kme[20], kmf[20];
i2 = j2 = 0;
for (k = 0; k < ndimen; k++){
tmp2 = 0.0;
for (i = k; i < ndimen; i++){
for (j = k; j < ndimen; j++){
if (fabs(mix[i][j] ) <= fabs(tmp2))
continue;
tmp2 = mix[i][j];
i2 = i;
j2 = j;
}
}
if (i2 != k