#define N 100
#define k 1
float X(int i) {
return (float) i / N;
}
float Y(int i) {
return sin(X(i));
}
float p(int i) {
return (float) (X(i) + 1) / (float) (2 - X(i));
}
float q(int i) {
return sqrt(cos(X(i)));
}
float r(int i) {
return (float) sqrt(3 * X(i) * X(i) + 10); // r(x)
return (float) sqrt(3 * X(i) * X(i) + 10) * (-1); // -r(x)
}
float A(int i) {
return (float) p(i) * N * N;
}
float B(int i) {
return (float) p(i) * N * N + (float) q(i) * N;
}
float C(int i) {
return ((float) 2 * p(i) * N * N + (float) q(i) * N - (float) r(i)) * (-1);
}
float F(int i) {
if (i != N-1)
return ((float) k * k * p(i) * sin(k * i) - (float) k * q(i) * cos(k * i) -
(float) r(i) * sin(k * i)) * (-1);
else
return ((float) k * k * p(i) * sin(k * i) - (float) k * q(i) * cos(k * i) -
(float) r(i) * sin(k * i)) * (-1) - (float) B(i) * sin(k);
}
int main() {
clrscr();
unsigned long StartMem = coreleft();
int i, j;
float V[N], U[N], a[N], b[N];
for (i = 1; i <= N-1; i++) {
if (i == 1) {
a[i] = (-1) * B(i) / C(i);
b[i] = F(i) / C(i);
}
else {
a[i] = (-1) * B(i) / (C(i) + A(i) * a[i-1]);
b[i] = (F(i) - A(i) * b[i-1]) / (C(i) + A(i) * a[i-1]);
}
/* cout << "a[" << i << "] = " <<
a[i] << "\t" <<
"b[" << i << "] = " << b[i] << "\n";*/
}
U[N] = (float) sin(k);
U[0] = 0;
U[N-1] = b[N-1];
for (i = N-2; i >= 1; i--) {
U[i] = a[i] * U[i+1] + b[i];
}
cout << "Reshenie dlya N = " << N << "\n";
cout << "Y - tochnoe reshenie; U - poluchenoe reshenie; V - pogreshnost:
\n";
for (i = 0; i <= N; i += 5)
cout << " Y(" << i << ") = " <<
Y(i) <<
"\tU(" << i << ") = " << U[i] <<
" \tV(" << i << ") = " << Y(i) - U[i]
<< "\n";
cout << "\nLost memory: " << StartMem - coreleft();
return 0;
};