#include <cstdlib>
#include <iostream>
using namespace std;
double scalar(double *a, double *b, int i)
{
double sum = 0;
for(i--;i >= 0; i--)
sum += a[i] * b[i];
return sum;
}
void vsum(double *a, double *b, int i)
{
for(i--;i >= 0; i--)
a[i] += b[i];
}
void vprod(double *a, double b, int i)
{
for(i--;i >= 0; i--)
a[i] *= b;
}
void vcopy(double *a, double *b, int i)
{
for(i--;i >= 0; i--)
a[i] = b[i];
}
double vmod(double *a, int i)
{
double sum = 0;
for(i--;i >= 0; i--)
sum += a[i] * a[i];
return sum;
}
int main(int argc, char *argv[])
{
double vect[10] = {0, 0.4, 0.5, 0, 0.2, 0.5, 2, 0, 0, 0};
double a[22][10] = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, -1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, -1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, -1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, -1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, -1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, -1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, -1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, -1, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}};
double b[22] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
bool NotOk = true;
while (NotOk)
{
NotOk = false;
for (int i = 0; i < 22; i++)
{
double d = scalar(vect, a[i], 10) - b[i];
if (d < 0)
{
NotOk = true;
double temp[10];
vcopy(temp, a[i], 10);
d = - d / vmod(temp, 10);
vprod(temp, d, 10);
vsum(vect, temp, 10);
}
}
}
for (int i = 0; i < 10; i ++)
cout << vect[i] << " ";
cout << endl << endl;
system("PAUSE");
return EXIT_SUCCESS;
}