Π‘Ρ
Π΅ΠΌΠ° Π°Π»Π³ΠΎΡΠΈΡΠΌΠ° ΡΡΠ½ΠΊΡΠΈΠΈ FI (k, x[i]).
ΠΠΎΠ΄ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ
#include.
#include.
#include.
#include.
#define m 3.
#define n 6.
void Massiv (float *M, char *Name, int x).
{.
int i, j;
printf («Array %s: «, Name);
for (j=0;j.
{.
printf («%5.3f «, M[j]);
}.
printf (««);
}.
void znachenia (float X[n], float Y[n]).
{.
int i;
printf («vvedite: «);
for (i=0;i.
{.
printf («X[%i]=», i+1);
scanf («%f» ,&X[i]);
printf («Y[%i]=», i+1);
scanf («%f» ,&Y[i]);
}.
}.
float F1(int k, float N).
{.
if (k==0) return 1;
if (k==1) return log (N);
else.
return N;
}.
void koefficent (float A[m][m], float B[m], float X[n], float Y[n]).
{.
int i, l, k;
for (i=0;i.
for (l=0;l.
{.
A[i][l] = 0;
for (k=0;k.
A[i][l]=A[i][l] + F1(i, X[k]) * F1(l, X[k]);
}.
for (k=0;k.
{.
B[k] = 0;
for (i=0;i.
B[k]=B[k]+Y[i]*F1(k, X[i]);
}.
}.
int ved (float A[m][m], int i).
{.
int g, h, k;
float MaxA;
h = -1;
MaxA = 0;
for (k=i;k.
if (fabs (A[k][i])>fabs (MaxA)).
{.
MaxA = A[k][i];
h = k;
}.
if (h == -1).
{.
printf («Matrix virogdena «);
abort ();
}.
return h;
}.
void perest (float A[m][m], float B [m], int i, int IM).
{.
float temp; int j;
if (IM ≠i).
{.
for (j=i;j.
{.
temp = A[i][j];
A[i][j] = A[IM][j];
A[IM][j] = temp;
}.
temp = B[i];
B[i] = B[IM];
B[IM] = temp;
}.
}.
void rkoef (float A[m][m], float B[m], int i, int l).
{.
int j; float Q;
Q=A[l][i] / A[i][i];
A[l][i] = 0;
for (j=i+1;j.
A[l][j] = A[l][j] - Q*A[i][j];
B[l]=B[l] - Q*B[i];
}.
void prgauss (float A[m][m], float B[m]).
{.
int i, IM, l, j;float Q;
for (i=0;i.
{.
IM = ved (A, i);
perest (A, B, i, IM);
for (l=i+1;l.
rkoef (A, B, i, l);
}.
for (i=0;i.
{.
for (j=0;j.
printf («%f «, A[i][j]);
printf (««);
}.
}.
void obrgauss (float A[m][m], float B[m], float C[m]).
{.
int k, j;float Sum;
C[m-1] = B[m-1] / A[m-1][m-1];
for (k = m — 2;k>=0;k—).
{.
Sum = B[k];
for (j=k+1;j.
Sum = Sum — A[k][j]*C[j];
C[k] = Sum / A[k][k];
}.
}.
void apr (float C[m], float X[n], float Y[n], float Y1[n], float D[n], float *Kr).
{.
int i;
*Kr=0;
for (i=0;i.
{.
Y1[i]=C[0]*F1(0,X[i])+C[1]*F1(1,X[i])+C[2]*F1(2,X[i]);
D[i]=fabs (Y[i]-Y1[i]);
*Kr=*Kr+D[i]*D[i];
}.
}.
void krappr (float D[n], float *Dmax, int *IM).
{.
int i;
for (i=0;i.
if (fabs (D[i])>fabs (*Dmax)).
{.
}.
}.
void vivodvsego (float C[m], float X[n], float Y1[n], float D[n], float Kr, float Dmax, int IM).
{.
Massiv (C, «C», m);
Massiv (Y1, «Y1», n);
Massiv (D, «D», n);
printf («Dmax = %5.3f pri X[%i] = %5.3f «, Dmax, IM+1,X[IM]);
printf («Kr = %5.4f «, Kr);
}.
int main ().
{.
float X[n], Y[n], A[m][m], B[m], C[m], Y1[n], D[n], Dmax, Q, Kr, Sum;
int i, j, IM;
znachenia (X, Y);
koefficent (A, B, X, Y);
printf («Massiv A «);
for (i=0; i.
{.
for (j=0; j.
printf («%f «, A[i][j]);
printf (««);
}.
Massiv (B, «B», m);
prgauss (A, B);
obrgauss (A, B, C);
apr (C, X, Y, Y1, D, &Kr);
krappr (D, &Dmax, &IM);
vivodvsego (C, X, Y1, D, Kr, Dmax, IM);
getch ();
return 0;
}.