@@ -273,7 +273,7 @@ static satRanges applyCorrectionOnPseudoRange(satRanges corrRanges, satRanges ps
273
273
// dimension of A[][]
274
274
static double ** getCofactor (double **A, int p, int q, int n)
275
275
{
276
- double ** temp = 0 ;
276
+ double ** temp = new double *[posMTrillatAColumSize] ;
277
277
int i = 0 , j = 0 ;
278
278
279
279
// Looping for each element of the matrix
@@ -329,7 +329,7 @@ static double clacDeterminant(double **A, int n)
329
329
// Function to get adjoint of A[N][N] in adj[N][N].
330
330
static double ** calcAdjoint (double **A, int matrixArows)
331
331
{
332
- double ** adj = 0 ;
332
+ double ** adj = new double *[matrixArows] ;
333
333
int sign = 0 ;
334
334
335
335
for (int i=0 ; i<matrixArows; i++)
@@ -355,7 +355,7 @@ static double** calcAdjoint(double **A, int matrixArows)
355
355
// method assumes that matrices have same dim sizes
356
356
static double ** multiplyMatrices (double **matrixA, double **matrixB, int matrixArows)
357
357
{
358
- double ** outputMatrix = 0 ;
358
+ double ** outputMatrix = new double *[posMTrillatAColumSize] ;
359
359
int i, j, k;
360
360
361
361
// Initializing elements of matrix mult to 0.
@@ -385,7 +385,7 @@ static double** multiplyMatrices(double **matrixA, double **matrixB, int matrixA
385
385
// method assumes that matrices have same dim sizes
386
386
static double ** multiplyMatricesND1D (double **matrixA, double **matrixB, int matrixArows)
387
387
{
388
- double ** outputMatrix = 0 ;
388
+ double ** outputMatrix = new double *[posMTrillatAColumSize] ;
389
389
int i, j, k;
390
390
391
391
// Initializing elements of matrix mult to 0.
@@ -411,12 +411,12 @@ static double** multiplyMatricesND1D(double **matrixA, double **matrixB, int mat
411
411
return outputMatrix;
412
412
}
413
413
414
- static double ** transpose2DimMatrix (double **inputArr)
414
+ static double ** transpose2DimMatrix (double **inputArr, int matrixArows, int transpose2DimMatrix )
415
415
{
416
- double **outputArr = 0 ;
417
- for (int i = 0 ; i < sizeof (**inputArr)/ sizeof ( double ) ; ++i)
416
+ double **outputArr = new double *[matrixArows] ;
417
+ for (int i = 0 ; i < matrixArows ; ++i)
418
418
{
419
- for (int j = 0 ; j < sizeof (*inputArr[ 0 ])/ sizeof ( double ) ; ++j)
419
+ for (int j = 0 ; j < transpose2DimMatrix ; ++j)
420
420
{
421
421
outputArr[j][i]= inputArr[i][j];
422
422
}
@@ -428,7 +428,7 @@ static double** transpose2DimMatrix(double **inputArr)
428
428
// matrix is singular by https://www.geeksforgeeks.org/adjoint-inverse-matrix/
429
429
static double ** calcInverse (double **A, int matrixArows)
430
430
{
431
- double ** inverse = 0 ;
431
+ double ** inverse = new double *[posMTrillatAColumSize] ;
432
432
// Find determinant of A[][]
433
433
int det = clacDeterminant (A, posMTrillatAColumSize);
434
434
if (det == 0 )
@@ -448,9 +448,9 @@ static double** calcInverse(double **A, int matrixArows)
448
448
return inverse;
449
449
}
450
450
451
- static double ** leastSquareReg (double **matrixA, double **matrixB, int matrixArows)
451
+ static double ** leastSquareReg (double **matrixA, double **matrixB, int matrixArows, int matrixAcol )
452
452
{
453
- double **matrixATransposed = transpose2DimMatrix (matrixA);
453
+ double **matrixATransposed = transpose2DimMatrix (matrixA, matrixArows, matrixAcol );
454
454
double **matrixATransposedA = multiplyMatrices (matrixATransposed, matrixA, matrixArows);
455
455
double **matrixATransposedAInverse = calcInverse (matrixATransposedA, matrixArows);
456
456
double **matrixATransposedAAdd = multiplyMatrices (matrixATransposedAInverse, matrixATransposed, matrixArows);
@@ -463,14 +463,14 @@ ecefPos trillatPosFromRange(satLocation finalSatPos, satRanges finalSatRanges)
463
463
{
464
464
std::map<int , ecefPos>::iterator it_;
465
465
std::map<int , double >::iterator finalSatRangesMap;
466
- int matrixArows,matrixAcol = 0 ;
466
+ int matrixArows, matrixAcol = 0 ;
467
467
double x, y, z;
468
468
double Am, Bm, Cm, Dm;
469
469
double range;
470
470
int nSat = finalSatPos.locations .size ();
471
471
ecefPos finalPos = { 0.0 , 0.0 , 0.0 };
472
- double **matrixA = 0 ;
473
- double **matrixB = 0 ;
472
+ double **matrixA = new double *[ 3 ] ;
473
+ double **matrixB = new double *[ 1 ] ;
474
474
475
475
matrixAcol = posMTrillatAColumSize;
476
476
matrixArows = nSat;
@@ -504,7 +504,7 @@ ecefPos trillatPosFromRange(satLocation finalSatPos, satRanges finalSatRanges)
504
504
}
505
505
506
506
// least square regression
507
- double **finalECEF = leastSquareReg (matrixA, matrixB, matrixArows);
507
+ double **finalECEF = leastSquareReg (matrixA, matrixB, matrixArows, matrixAcol );
508
508
509
509
finalPos.x = *finalECEF[0 ];
510
510
finalPos.y = *finalECEF[1 ];
0 commit comments