Home c++ The problem of calculating the return matrix with the type Float

The problem of calculating the return matrix with the type Float

Author

Date

Category

It is necessary to calculate the number of conditionality of the matrix by definition and give an estimate from below for this number (that is, experimental assessment).

The number of conditionality by definition: Conda = || A ^ (- 1) || * || A ||. The fact is that before this task in the program, the Gauss method was implemented to solve the Slava and the QR decomposition method. To turn the matrix (A Dana Matrix 4×4), then I simply solve four equations where the right side first (1,0,0,0,0), (0,1,0,0), (0,0,1,0) , (0,0,0,1). I get a reverse matrix, I multiply on the original and get a single one. Everything is good, however, we picked up such a matrix, at which it is not a single one with the type “float” with multiplies. With the type “Double” everything is fine, but it is with “Float” – nonsense.


Matrix itself (it is in the read file):

0.2910 1.8100 9.3110 9.1100 4.2280
 1.4500 8.5790 44.1950 42.9950 20.4290
 -0.2900 -1.7980 -9.2500 -9.0500 -4.2080
 0.0000 0.0820 0.4100 0.4500 0.1220

When multiplying the original matrix (see) and the reverse is not quite a single matrix (in some places there are numbers in the spirit of 0.06, etc.)
I repeat once again, this happens only with the type “Float”. For the code, I will not particularly scold, I know that it is cluttered strongly.

# include & lt; iostream & gt;
#InClude & lt; Iomanip & gt;
#Include & lt; Cmath & GT;
#Include & lt; fstream & gt;
#Include & lt; float.h & gt;
Using Namespace STD;
TypeDef Float TDouble;
const TDOUBLE EPS = 1E-16; // at 1E-8 Data9 does not work
const unsigned n = 4;
Void Product (TDOUBLE **, TDOUBLE *, TDOUBLE *);
Void Product (TDOUBLE **, TDOUBLE **, TDOUBLE **);
Void Output (TDOUBLE **, TDOUBLE *);
Void Output (TDOUBLE *);
Void Output (TDOUBLE **);
void changing (tduble **, tdouble *, int, int);
BOOL GAUSSS (TDOUBLE **, TDOUBLE *);
Void QR (TDOUBLE **, TDOUBLE *, TDOUBLE **);
Void QR (TDOUBLE **, TDOUBLE *, TDOUBLE *, TDOUBLE *, TDOUBLE *, TDOUBLE **);
Void Reverse (TDOUBLE **, TDOUBLE *, TDOUBLE *);
Void SPHERICAL (TDOUBLE *, TDOUBLE *)
TDOUBLE OCTAHEDRON (TDOUBLE *);
TDOUBLE OCTAHEDRON (TDOUBLE *, TDOUBLE *);
TDOUBLE CUBIC (TDOUBLE *, TDOUBLE *);
TDOUBLE CUBIC (TDOUBLE *);
TDOUBLE CUBIC_MATRIX (TDOUBLE **);
TDOUBLE OCTAH_MATRIX (TDOUBLE **);
INT MAIN ()
{
SETLOCALE (LC_ALL, "RUSSIAN");
TDOUBLE ** MTX, ** MTXUN, * VECT, * VECTUN;
MTX = new TDouble * [n]; // Array of pointers
mtxun = new tdouble * [n]; // Unchanging matrix
VECT = NEW TDOUBLE [N];
VECTUN = NEW TDOUBLE [N];
ifstream filemat;
Filemat.open ("U: \\ FS13 \\ FS2-X3 \\ Melikhov \\ Metody_vych \\ Llaba1 \\ Data9.txt");
for (int i = 0; i & lt; n; i ++)
{
  MTXUN [i] = new tdouble [n];
  MTX [i] = new tdouble [n];
  for (int j = 0; j & lt; n + 1; j ++)
  {
    FileMat & gt; & gt; (j == 4? VECT [I]: MTX [i] [J]); //if
    J == 4? VECTUN [I] = VECT [I]: MTXUN [I] [J] = MTX [I] [J];
  }
}
filemat.close ();
COUT & LT; & LT; "\ t \ TRIVE of the original matrix and vector of the right part" & lt; & lt; Endl & lt; & lt; Endl;
OUTPUT (MTX, VECT); // Conclusion on the screen matrix and right vector
// Check for degeneracy
BOOL H = GAUSSS (MTX, VECT);
TDOUBLE PRODUCT_DIAGONAL_ELEMENTS = MTX [0] [0]; // Production of diagonal elements (for checking degeneracy)
For (int i = 1; i & lt; n; i ++)
  Product_Diagonal_Elements * = MTX [i] [i];
if (! H || ABS (product_diagonal_elements) & lt; eps) // If the module of the product of the diagonal elements is less than the epsilon, then the message output
{
  COUT & LT; & LT; "Matrix degenerate. Goodbye!";
}
ELSE // Other
{
  TDOUBLE * SOL = NEW TDOUBLE [N], * Check = New TDouble [n];
  tdouble * sin1 = new tdouble [n], * sin2 = new tdouble [n], * sin3 = new tdouble [n], * sin4 = new tdouble [n]; // Single Right Part
  TDOUBLE * SOLR1 = NEW TDOUBLE [N], * SOLR2 = NEW TDOUBLE [N], * SOLR3 = NEW TDOUBLE [N], * SOLR4 = NEW TDOUBLE [N]; // decision with a single right
  TDOUBLE * SOLV1 = NEW TDOUBLE [N], * SOLV2 = NEW TDOUBLE [N], * SOLV3 = NEW TDOUBLE [N], * SOLV4 = NEW TDOUBLE [N]; // decision with a single right 
TDOUBLE ** MTXRev = New TDouble * [N]; //inverse matrix
  TDOUBLE NUN_CUB, NREV_CUB, CONDEX_CUB; // Norma source, rate reverse, number of conditionality
  TDOUBLE NUN_OCT, NREV_OCT, CONDEX_OCT;
  for (int i = 0; i & lt; n; i ++)
  {
    (i == 0? sin1 [i] = 1: sin1 [i] = 0);
    (i == 1? sin2 [i] = 1: sin2 [i] = 0);
    (i == 2? sin3 [i] = 1: sin3 [i] = 0);
    (i == 3? sin4 [i] = 1: sin4 [i] = 0);
  }
  // Lead to the original form MTX and VECT
  tduble ** t = new tdouble * [n], ** mtxcheck = new tdouble * [n]; // Create a new array T - a single matrix. It will be needed to obtain the matrix q
  for (int i = 0; i & lt; n; i ++)
  {
    T [i] = new tdouble [n];
    mtxrev [i] = new tdouble [n];
    MtxCheck [i] = New TDouble [n];
    for (int j = 0; j & lt; n; j ++)
    {
      T [i] [j] = (i == j? 1: 0); // If i = j, then we assign 1, otherwise - 0
      MTX [i] [j] = mtxun [i] [j]; // in MTX write the unchanging MTXUN matrix to restore the first
    }
    VECT [i] = VECTUN [I]; // Similarly to the vector
  }
  // QR-method
  QR (MTX, VECT, SIN1, SIN2, SIN3, SIN4, T);
  //// Transparenpute T in Q, create an array a
  tduble ** q = new tdouble * [n], ** a = new tdouble * [n];
  for (int i = 0; i & lt; n; i ++)
  {
    Q [i] = new tdouble [n];
    A [i] = new tdouble [n];
    for (int j = 0; j & lt; n; j ++)
      Q [i] [j] = t [j] [i];
  }
  // Find a reverse matrix
  Reverse (MTX, SIN1, SOLR1);
  Reverse (MTX, SIN2, SOLR2);
  Reverse (MTX, SIN3, SOLR3);
  Reverse (MTX, SIN4, SOLR4);
  for (int j = 0; j & lt; n; j ++)
  {
    for (int i = 0; i & lt; n; i ++)
    {
      if (j == 0)
        Mtxrev [i] [j] = Solr1 [i];
      ELSE.
        if (j == 1)
          mtxrev [i] [j] = Solr2 [i];
        ELSE.
          if (j == 2)
            Mtxrev [i] [j] = Solr3 [i];
          ELSE.
            if (j == 3)
              mtxrev [i] [j] = Solr4 [i];
    }
  }
  COUT & LT; & LT; "Reverse matrix" & lt; & lt; Endl;
  Output (MTXRev);
  Product (MTXUN, MTXRev, MtxCheck);
  COUT & LT; & LT; "Check" & lt; & lt; Endl;
  Output (MtxCheck);
  COUT & LT; & LT; Endl & lt; & lt; Endl & lt; & lt; "Cubic norm" & lt; & lt; Endl;
  NUN_CUB = CUBIC_MATRIX (MTXUN);
  NREV_CUB = CUBIC_MATRIX (MTXRev);
  CONDEX_CUB = NUN_CUB * NREV_CUB;
  COUT & LT; & LT; Endl & lt; & lt; "The norm of the initial matrix =" & lt; & lt; nun_cub & lt; & lt; Endl & lt; & lt; "Reverse matrix rate =" & lt; & lt; nrev_cub & lt; & lt; Endl & lt; & lt; "Work norm =" & lt; & lt; CONDEX_CUB & LT; & LT; Endl;
  COUT & LT; & LT; Endl & lt; & lt; Endl & lt; & lt; "Octahedral norm" & lt; & lt; Endl;
  nun_oct = octah_matrix (MTXUN);
  nrev_oct = octah_matrix (mtxrev);
  CONDEX_OCT = NUN_OCT * NREV_OCT;
  COUT & LT; & LT; Endl & lt; & lt; "The norm of the initial matrix =" & lt; & lt; Nun_Oct & lt; & lt; Endl & lt; & lt; "Reverse matrix rate =" & lt; & lt; NREV_OCT & LT; & LT; Endl & lt; & lt; "Work norm =" & lt; & lt; CONDEX_OCT & LT; & LT; Endl;
  // Return
  Reverse (MTX, VECT, SOL);
  TDOUBLE N_DX, N_DB, // DV, DB differences
      NX_D, NB_D, // Laying Norms X, B
      N_X, N_B; // Norma X and B
  TDOUBLE MAX_DIV, NORM_DIV; // Maximum division, division rate
  TDOUBLE O_DX, O_DB, OX_D, OB_D, O_X, O_B, MAXO_DIV, NORMO_DIV; // Octahedrical
  n_x = cubic (SOL);
  O_x = Octahedron (SOL);
  // COUT & LT; & LT; Endl & lt; & lt; "n_x" & lt; & lt; N_X & LT; & LT; Endl;
  n_b = cubic (VectUN);
  O_B = Octahedron (VectUN);
  // COUT & LT; & LT; Endl & lt; & lt; "n_b" & lt; & lt; N_B & LT; & LT; Endl;
  max_div = 0;
  maxo_div = 0;
  // lead to the original type of vect and mtx
  for (int i = 0; i & lt; n; i ++)
  {
    for (int j = 0; j & lt; n; j ++)
      MTX [i] [j] = mtxun [i] [j];
    VECT [i] = VECTUN [I];
  }
  for (int i = 0; i & lt; n; i ++)
  {
    vect [i] + = 0.01; // Remick the i-th vectors component vect
    // COUT & LT; & LT; "VECT" & lt; & lt; Endl;
    // OUTPUT (vect);
    n_db = cubic (vect, vectun);
    O_DB = Octahedron (Vect, Vectun);
    // COUT & LT; & LT; Endl & lt; & lt; "n_db" & lt; & lt; n_db & lt; & lt; Endl; 
QR (MTX, VECT, T);
    REVERSE (MTX, VECT, SOLV1);
    // COUT & LT; & LT; Endl; OUTPUT (SOLV1); COUT & LT; & LT; Endl;
    for (int k = 0; k & lt; n; k ++)
    {
      for (int j = 0; j & lt; n; j ++)
        mtx [k] [j] = mtxun [k] [j];
      vect [k] = vectun [k];
    }
    n_dx = cubic (SOLV1, SOL);
    O_DX = Octahedron (SOLV1, SOL);
    // COUT & LT; & LT; Endl & lt; & lt; "n_dx" & lt; & lt; n_dx & lt; & lt; Endl;
    nx_d = n_dx / n_x;
    OX_D = O_DX / O_X;
    // COUT & LT; & LT; Endl & lt; & lt; "nx_d" & lt; & lt; nx_d & lt; & lt; Endl;
    nb_d = n_db / n_b;
    OB_D = O_DB / O_B;
    // COUT & LT; & LT; Endl & lt; & lt; "nb_d" & lt; & lt; NB_D & LT; & LT; Endl;
    NORM_DIV = NX_D / NB_D;
    NORMO_DIV = OX_D / OB_D;
    // COUT & LT; & LT; Endl & lt; & lt; "norm_div" & lt; & lt; NORM_DIV & LT; & LT; Endl;
    if (max_div & lt; norm_div) max_div = norm_div;
    if (maxo_div & lt; norm_div) maxo_div = normo_div;
  }
  COUT & LT; & LT; Endl & lt; & lt; "Assessment from below (cubic norm):" & lt; & lt; MAX_DIV & LT; & LT; Endl;
  COUT & LT; & LT; Endl & lt; & lt; "Abmount estimate (octahedral norm):" & lt; & lt; MAXO_DIV & LT; & LT; Endl;
  delete [] sin1;
  delete [] sin2;
  delete [] sin3;
  delete [] sin4;
  Delete [] Check;
  DELETE [] SOL;
  for (int i = 0; i & lt; n; i ++)
  {
    delete [] a [i];
    DELETE [] Q [i];
    delete [] t [i];
  }
  delete [] a;
  delete [] q;
  DELETE [] T;
}
cin.get ();
Delete [] vect;
Delete [] Vectun;
for (int i = 0; i & lt; n; i ++)
{
  DELETE [] MTX [I];
  DELETE [] MTXUN [I];
}
Delete [] MTX;
DELETE [] MTXUN;
}
Void Reverse (TDOUBLE ** MTX, TDOUBLE * VECT, TDOUBLE * SOL)
{
// Return speed /
for (int i = n - 1; i & gt; = 0; i--)
{
  TDOUBLE TEMP = 0;
  for (int j = i + 1; j & lt; n; j ++) // The cycle will not pass from the first time, so it will not be found an empty array of SOL [J] first, but will detect only after the first iteration of the external cycle
    TEMP + = MTX [I] [J] * SOL [J];
  Sol [i] = (vect [i] - temp) / mtx [i] [i];
}
}
BOOL GAUSSS (TDOUBLE ** MTX, TDOUBLE * VECT)
{
TDOUBLE C; // Scaling coefficient
For (int j = 0; j & lt; n; j ++) // Moving on columns
{
  TDOUBLE TEMP = ABS (MTX [J] [J]); // We are looking for a maximum of a column, remembering J, the j-th element (we are always diagonally and below)
  int mem = j; // variable to memorize the number of the line where the maximum is searched
  for (int i = j + 1; i & lt; n; i ++) // from j + 1, because under the diagonal we are looking for the maximum element
    IF (Temp & Lt; ABS (MTX [i] [J]))
    {
      TEMP = ABS (MTX [I] [J]); // remember a new maximum
      mem = i; // remember the corresponding string
    }
  if (Temp & LT; EPS) Return False; // if the maximum is comparable to zero, then we return false, that is, the program is meaningless
  Changing (MTX, VECT, MEM, J); // change lines in places
  for (int i = j + 1; i & lt; n; i ++) // cycle to calculate scaling and conversion coefficients
  {
    c = mtx [i] [j] / mtx [j] [j];
    for (int k = j; k & lt; n; k ++)
      MTX [I] [K] - = C * MTX [J] [k]; // Recalling the I-RD in the matrix (linear combination) ...
    vect [i] - = C * vect [j]; // ... and in vector
  }
}
RETURN TRUE; // Return Truth
}
Void QR (TDOUBLE ** MTX, TDOUBLE * VECT, TDOUBLE ** T) // Principle: We change the line to the row so that there is no division to zero. Then we calculate the coefficients and replace the lines on linear combinations
{
// QR-method
for (int k = 0; k & lt; n; k ++) // go on line
{
  // int z = k; // remember the line number
  // WHILE (ABS (MTX [Z] [K]) & lt; EPS & amp; & amp; z & lt; n) // While the zero element, increase Z, storage string. It is also checked outside the array.
  // z ++;
  // if (z! = K)
  // Changing (MTX, VECT, Z, K);
  TDOUBLE C, S, TEMP_SQR; // C, S - Coefficients, Temp_SQR - Temporary root
  For (int i = k + 1; i & lt; n; i ++) // We move on the line down and consider:
  {// Counting coefficients
    IF (ABS (MTX [I] [K]) & lt; EPS) Continue;
    temp_sqr = sqrt (mtx [k] [k] * mtx [k] [k] + mtx [i] [k] * mtx [i] [k]);
    C = MTX [K] [K] / TEMP_SQR;
    S = MTX [I] [K] / TEMP_SQR;
    TDOUBLE TEMP, TEMPT; 
For (int j = 0; j & lt; n; j ++) // k
    {// Replacement on linear combinations
      TEMPT = T [K] [J];
      T [k] [j] = c * t [k] [j] + s * t [i] [j];
      T [i] [j] = -s * tempt + c * t [i] [j];
      if (j & gt; = k) // In order not to recount zeros
      {
        temp = mtx [k] [j]; // Keep the first string in a temporary variable
        MTX [K] [J] = C * MTX [K] [J] + S * MTX [I] [J]; // Replace the K-RT line on the LC with C and S coefficients
        MTX [i] [J] = -S * TEMP + C * MTX [i] [J]; // We replace the J-line line on the LC using the initial K-th line
      }
    } // Similarly to the vector of the right part
    temp = vect [k];
    vect [k] = c * vect [k] + s * vect [i];
    vect [i] = -s * TEMP + C * VECT [i];
  }
}
}
Void QR (TDOUBLE ** MTX, TDOUBLE * VECT, TDOUBLE * SIN1, TDOUBLE * SIN2, TDOUBLE * SIN3, TDOUBLE * SIN4, TDOUBLE ** T) // Principle: We change the string in such a way so that there is no division to zero. Then we calculate the coefficients and replace the lines on linear combinations
{
// QR-method
for (int k = 0; k & lt; n; k ++) // go on line
{
  // int z = k; // remember the line number
  // WHILE (ABS (MTX [Z] [K]) & lt; EPS & amp; & amp; z & lt; n) // While the zero element, increase Z, storage string. It is also checked outside the array.
  // Z ++;
  // if (z! = K)
  // Changing (MTX, VECT, Z, K);
  TDOUBLE C, S, TEMP_SQR; // C, S - Coefficients, Temp_SQR - Temporary root
  For (int i = k + 1; i & lt; n; i ++) // We move on the line down and consider:
  {// Counting coefficients
    IF (ABS (MTX [I] [K]) & lt; EPS) Continue;
    temp_sqr = sqrt (mtx [k] [k] * mtx [k] [k] + mtx [i] [k] * mtx [i] [k]);
    C = MTX [K] [K] / TEMP_SQR;
    S = MTX [I] [K] / TEMP_SQR;
    TDOUBLE TEMP, TEMPT;
    For (int j = 0; j & lt; n; j ++) // k
    {// Replacement on linear combinations
      TEMPT = T [K] [J];
      T [k] [j] = c * t [k] [j] + s * t [i] [j];
      T [i] [j] = -s * tempt + c * t [i] [j];
      if (j & gt; = k) // In order not to recount zeros
      {
        temp = mtx [k] [j]; // Keep the first string in a temporary variable
        MTX [K] [J] = C * MTX [K] [J] + S * MTX [I] [J]; // Replace the K-RT line on the LC with C and S coefficients
        MTX [i] [J] = -S * TEMP + C * MTX [i] [J]; // We replace the J-line line on the LC using the initial K-th line
      }
    } // Similarly to the vector of the right part
    temp = vect [k];
    vect [k] = c * vect [k] + s * vect [i];
    vect [i] = -s * TEMP + C * VECT [i];
    TEMP = SIN1 [K];
    sin1 [k] = c * sin1 [k] + s * sin1 [i];
    sin1 [i] = -s * TEMP + C * SIN1 [i];
    temp = sin2 [k];
    sin2 [k] = c * sin2 [k] + s * sin2 [i];
    SIN2 [I] = -S * TEMP + C * SIN2 [i];
    temp = sin3 [k];
    sin3 [k] = c * sin3 [k] + s * sin3 [i];
    sin3 [i] = -s * TEMP + C * SIN3 [i];
    TEMP = SIN4 [K];
    sin4 [k] = c * sin4 [k] + s * sin4 [i];
    SIN4 [I] = -S * TEMP + C * SIN4 [i];
  }
}
}
Void Product (TDOUBLE ** MTX, TDOUBLE * SOL, TDOUBLE * CHECK)
{
For (int i = 0; i & lt; n; i ++) // fixed the string
{
  Check [i] = 0;
  For (int j = 0; j & lt; n; j ++) // Moving on columns and ....
    Check [i] + = MTX [i] [J] * SOL [J]; // Alternatively
}
}
Void Product (TDOUBLE ** MTXUN, TDOUBLE ** MTXREV, TDOUBLE ** MTXCHECK)
{
for (int i = 0; i & lt; n; i ++)
  for (int j = 0; j & lt; n; j ++)
    MtxCheck [i] [j] = 0;
for (int i = 0; i & lt; n; i ++)
{
  for (int j = 0; j & lt; n; j ++)
  {
    for (int m = 0; m & lt; n; m ++)
    {
      MtxCheck [i] [j] + = mtxun [i] [m] * mtxrev [m] [j];
    }
  }
}
}
Void Output (TDOUBLE * SOL)
{
for (int i = 0; i & lt; n; i ++)
  COUT & LT; & LT; Fixed & lt; & lt; SetPrecision (4) & lt; & lt; SETW (42) & lt; & lt; Sol [i] & lt; & lt; Endl;
}
Void Output (TDOUBLE ** MTX, TDOUBLE * VECT)
{
For (int i = 0; i & lt; n; i ++) // fixed the string
{
  for (int j = 0; j & lt; n + 1; j ++) // went through columns
    COUT & LT; & LT; Fixed & lt; & lt; SetPrecision (4) & lt; & lt; SETW (14) & lt; & lt; (j == n? Vect [i]: mtx [i] [j]); // if j == n, then output vector (last column), otherwise - matrix
  COUT & LT; & LT; Endl;
}
} 
void output (tdouble ** mtx)
{
for (int i = 0; i & lt; n; i ++) // fixed the string
{
  for (int j = 0; j & lt; n; j ++) // let's go through the columns
    cout & lt; & lt; fixed & lt; & lt; setprecision (4) & lt; & lt; setw (14) & lt; & lt; mtx [i] [j]; // if j == n, then output the vector (the last column), otherwise - the matrix
  cout & lt; & lt; endl;
}
}
void changing (tdouble ** mtx, tdouble * vect, int line1, int line2)
{
tdouble * t = mtx [line2]; // remember the address
mtx [line2] = mtx [line1];
mtx [line1] = t;
tdouble r = vect [line2];
vect [line2] = vect [line1];
vect [line1] = r;
}
void spherical (tdouble * vectun, tdouble * check)
{
tdouble diff, diff2 = diff = 0.0;
for (int i = 0; i & lt; n; i ++)
{
  diff + = (vectun [i] - check [i]) * (vectun [i] - check [i]);
  diff2 + = vectun [i] * vectun [i] - 2 * vectun [i] * check [i] + check [i] * check [i];
}
cout & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ t Spherical discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; & lt; & lt; setw (14) & lt; & lt; diff2 & lt; & lt; endl;
// os & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ t Spherical discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; & lt; & lt; setw (14) & lt; & lt; diff2 & lt; & lt; endl;
}
tdouble octahedron (tdouble * vectun)
{
tdouble diffo_2 = 0.0;
for (int i = 0; i & lt; n; i ++)
  diffo_2 + = abs (vectun [i]);
 // cout & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ tOctahedral discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; endl;
return diffo_2;
 // os & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ tOctahedral discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; endl;
}
tdouble octahedron (tdouble * vectun, tdouble * check)
{
 tdouble diffo_1 = 0.0;
 for (int i = 0; i & lt; n; i ++)
  diffo_1 + = abs (vectun [i] - check [i]);
// cout & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ tOctahedral discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; endl;
return diffo_1;
// os & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ tOctahedral discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; endl;
 }
 tdouble cubic (tdouble * vectun, tdouble * check)
 {
tdouble diffc_1 = abs (vectun [0] - check [0]); // the maximum of the module is searched for = & gt; remember the very first difference, and then compare with it
for (int i = 1; i & lt; n; i ++)
{
  if (diffc_1 & lt; abs (vectun [i] - check [i]))
    diffc_1 = abs (vectun [i] - check [i]);
}
// cout & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ t Cubic discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; endl;
return diffc_1;
// os & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ t Cubic discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; endl;
}
tdouble cubic (tdouble * vectun)
{
tdouble diffc_2 = abs (vectun [0]); // the maximum of the module is searched for = & gt; remember the very first difference, and then compare with it
for (int i = 1; i & lt; n; i ++)
{
  if (diffc_2 & lt; abs (vectun [i]))
    diffc_2 = abs (vectun [i]);
}
// cout & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ t Cubic discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; endl;
return diffc_2;
// os & lt; & lt; scientific & lt; & lt; endl & lt; & lt; "\ t \ t \ t \ t Cubic discrepancy" & lt; & lt; endl & lt; & lt; setw (14) & lt; & lt; diff & lt; & lt; endl;
}
tdouble cubic_matrix (tdouble ** mtxun)
{
tdouble norm = 0;
tdouble maxn = norm;
for (int i = 0; i & lt; n; i ++)
{
  for (int j = 0; j & lt; n; j ++)
    norm + = abs (mtxun [i] [j]);
  if (norm & gt; maxn)
    maxn = norm;
  norm = 0;
}
norm = maxn;
return norm;
}
tdouble octah_matrix (tdouble ** mtxun)
{
tdouble norm = 0;
tdouble maxn = norm;
for (int i = 0; i & lt; n; i ++)
{
  for (int j = 0; j & lt; n; j ++)
    norm + = abs (mtxun [j] [i]);
  if (norm & gt; maxn)
    maxn = norm;
  norm = 0;
}
norm = maxn;
return norm;
}

Answer 1, authority 100%

Well, actually, which is to be expected. The data type float takes (usually) 4 bytes, and double – 8, there is also long double , it is 10 bytes. Accordingly, the more space per type, the more information it stores and the more accurate the calculation result.

If you calculate the number of conditionality , then you understand that it is essentially an indicator how much the calculation errors will affect the end result (the longer the number of the longer the error).

So write double (and better Long ). If after that, the result does not suit, it makes sense to read about compensating calculations, increasing accuracy and so on. Perhaps it will help you “all, dot, sailed! Learning to work with floating point numbers and develop an alternative with a fixed accuracy of decimal fraction . “

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions