hi!

i wanted to do some more numerical steps. I have got the induvidual functions but am struggling

to piece them together, basically because my c structure & syntax knowledge isnt so good ...

The outline of my problem once again :

I have 4 sensors giving me values & they are saved in a table along with the "serial number" & a parameter- distance ( d )

( see 1st post for table )

i have tried to save the things in a struct. I then caluclated a second distance "a" with a formula & then wanted to sort the values a

in order to get the 5 "groups" of readings with the smallest "a" ...

Then i wanted to calculate ( using the gauss jordan algo ) the coefficients lam2, ... lam5. The FUnction for the algo is at the bottom & should be correct

The gauß jordan algo, basically calculates Ax = B ... I tried to fill matrix A using Sys ...In the matrix b have a term s[0] ... this is my actuall

reading which i get in.

Finally using lam2...lam5 i calculate a distance d0 ...in the equation again the distances of the 5 earlier selected "groups comein.

Would be terrific if someone could suggesst ammendments to my code m so that it does what i want ...

Here m attempt so far :

Code:

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "..\cbw.h"
void main ()
{
struct Sensor
{
int nr,d,n ;
double s1,s2,s3,s4;
};
struct s[100];
for ( i=0;i<n;i++)
{
a[i] = sqrt( ( s[i].s1 -s11) * (s[i].s1 - s11 ) + (s[i].s2 - s12 )*( s[i].s2 - s12 ) + (s[i].s3 - s13) * (s[i].s3-s13) + ( s[i].s4 - s14 ) * ( s[i].s4 - s14 ) );
}
for (s[i] = 0; i < n; i++)
numbers[i] = s[i];
//perform bubble sort on array
bubbleSort(s[i].a, n);
for (i = 0; i < 4; i++)
printf("%i\n", s[i].a[i]);
gj4(double Sys_[4][5], double *x_, double *b_)
{
Sys_[0][0]= s[1].s1;
Sys_[0][1]= s[2].s1 - s[1].s1;
Sys_[0][2]= s[3].s1 - s[1].s1;
Sys_[0][3]= s[4].s1 - s[1].s1;
Sys_[0][4]= s[5].s1 - s[1].s1;
Sys_[1][0]= s[1].s2;
Sys_[1][1]= s[2].s2 - s[1].s2;
Sys_[1][2]= s[3].s2 - s[1].s2;
Sys_[1][3]= s[4].s2 - s[1].s2;
Sys_[1][4]= s[5].s2 - s[1].s2;
Sys_[2][0]= s[1].s3;
Sys_[2][1]= s[2].s3 - s[1].s3;
Sys_[2][2]= s[3].s3 - s[1].s3;
Sys_[2][3]= s[4].s3 - s[1].s3;
Sys_[2][4]= s[5].s3 - s[1].s3;
Sys_[3][0]= s[1].s4;
Sys_[3][1]= s[2].s4 - s[1].s4;
Sys_[3][2]= s[3].s4 - s[1].s4;
Sys_[3][3]= s[4].s4 - s[1].s4;
Sys_[3][4]= s[5].s4 - s[1].s4;
double b_[4] = {s[0].s1, s[0].s2, s[0].s3, s[0].s4};
double x_[5] = {1, (int)lam2, (int)lam3, (int)lam4};
if (gj4(Sys_, x_, b_)==0)
{
printf("Matrix ist singulär.\n");
isNearest = true;
break;
break;
}
}
s[0].d0 = s[1].d1 + (int)lam2 * ( s[2].d2 - s[1].d1 ) + (int)lam3 * ( s[3].d3 - s[1].d1 ) + (int)lam4 * ( s[4].d4 - s[1].d1 ) + (int)lam5 * ( s[5].d5 - s[1].d1 );
}
void bubbleSort(int numbers[], int array_size)
{
int i, j, temp;
for (i = (array_size - 1); i >= 0; i--)
{
for (j = 1; j <= i; j++)
{
if (numbers[j-1] > numbers[j])
{
temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp;
}
}
}
}
// Gauss-Jordan-Elimination
int gj4(double Sys_[4][5], double *x_, double *b_)
{
int col_a, row_a, col_i, row_i, switch1;
int pivot_a[] = {0, 0, 0, 0};
int pivot_i[] = {0, 0, 0, 0, 0};
double help1, help2;
for(col_a=0; col_a<5; col_a++)
{
for(row_a=0; row_a<4; row_a++)
{
if (Sys_[row_a][col_a]!=0 && pivot_a[row_a]!=1)
{
pivot_a[row_a] = 1;
pivot_i[row_a] = 1;
help1 = Sys_[row_a][col_a];
for(col_i=0; col_i<4; col_i++)
{
Sys_[row_a][col_i] = Sys_[row_a][col_i]/help1;
}
b_[row_a] = b_[row_a]/help1;
for(row_i=0; row_i<4; row_i++)
{
help2 = Sys_[row_i][col_a];
if (pivot_i[row_i]!=1 && help2!=0)
{
b_[row_i] = b_[row_i]-b_[row_a]*help2;
for(col_i=0; col_i<4; col_i++)
{
Sys_[row_i][col_i] = Sys_[row_i][col_i]-Sys_[row_a][col_i]*help2;
}
}
}
pivot_i[row_a] = 0;
}
}
}
for(row_a=0; row_a<4; row_a++)
{
switch1 = 0;
for(col_a=0; col_a<4; col_a++)
{
if (Sys_[row_a][col_a]==1)
{
x_[col_a] = b_[row_a];
switch1 = 1;
}
}
if (switch1==0)
{
}
}
return 1;
}