1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include<iostream>
#include<cmath>
#include<cstdio>
#include<stdio.h>
#include<fstream>
using namespace std;
int main()
{
double C[3], er, er0, a[3][4];
FILE* fp;
fp = fopen("datafile.dat", "r+");
fscanf(fp, " %1f, %1f, %1f, %1f, %1f, %1f, %1f, %1f, %1f, %1f, %1f, %1f, ", &a[0][0], &a[0][1], &a[0][2], &a[0][3], &a[1][0], &a[1][1], &a[1][2], &a[1][3], &a[2][0], &a[2][1], &a[2][2], &a[2][3]);
C[0] = a[0][3] / a[0][0];
C[1] = a[1][3] / a[1][1];
C[2] = a[2][3] / a[2][2];
er=5e-10;
er0=0;
int n;
while (n)
{
C[0] = (a[0][3] - C[1] * a[0][1] - C[2] * a[0][2]) / a[0][0];
C[1] = (a[1][3] - C[0] * a[1][0] - C[2] * a[1][2]) / a[1][1];
C[2] = (a[2][3] - C[0] * a[2][0] - C[1] * a[2][1]) / a[2][2];
if ( ((C[1]-er0)/C[1])<er)
{
n=0;
}
er0=C[1];
}
FILE *fp1;
fp1 = fopen("results.dat","w+");
fprintf(fp1,"C[1] = %8.4f \n",C[0]);
fprintf(fp1,"C[2] = %8.4f \n",C[1]);
fprintf(fp1,"C[3] = %8.4f \n",C[2]);
}
|