You can now raise a matrix to a negative power and store the resulting matrixes from an operation with a scalar in another matrix
case FILL:
printf("What matrix would you like to fill with a number?\n");
case FILL:
printf("What matrix would you like to fill with a number?\n");
+ do{
+ printf("Matrix A (0), B (1) or C (2)? ");
+ scanf("%d", &d);
+ }while(d < 0 || d > 2);
+ printf("Where would you like to store the resulting matrix?\n");
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to fill matrix %s?\n",
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to fill matrix %s?\n",
- (s==0)?"A":(s==1)?"B":"C");
+ (d==0)?"A":(d==1)?"B":"C");
- matrices[s] = fillN(matrices[s], n);
+ matrices[s] = fillN(matrices[d], n);
break;
case ADD_N:
printf("What matrix would you like to add a number to?\n");
break;
case ADD_N:
printf("What matrix would you like to add a number to?\n");
+ do{
+ printf("Matrix A (0), B (1) or C (2)? ");
+ scanf("%d", &d);
+ }while(d < 0 || d > 2);
+ printf("Where would you like to store the resulting matrix?\n");
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to add to matrix %s?\n",
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to add to matrix %s?\n",
- (s==0)?"A":(s==1)?"B":"C");
+ (d==0)?"A":(d==1)?"B":"C");
- matrices[s] = addN(matrices[s], n);
+ matrices[s] = addN(matrices[d], n);
break;
case SUBSTRACT_N:
printf("What matrix would you like to substract a number from?\n");
break;
case SUBSTRACT_N:
printf("What matrix would you like to substract a number from?\n");
+ do{
+ printf("Matrix A (0), B (1) or C (2)? ");
+ scanf("%d", &d);
+ }while(d < 0 || d > 2);
+ printf("Where would you like to store the resulting matrix?\n");
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to substract from matrix %s?\n",
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to substract from matrix %s?\n",
- (s==0)?"A":(s==1)?"B":"C");
+ (d==0)?"A":(d==1)?"B":"C");
- matrices[s] = substractN(matrices[s], n);
+ matrices[s] = substractN(matrices[d], n);
break;
case MULTIPLY_N:
printf("What matrix would you like to multiply by a number?\n");
break;
case MULTIPLY_N:
printf("What matrix would you like to multiply by a number?\n");
+ do{
+ printf("Matrix A (0), B (1) or C (2)? ");
+ scanf("%d", &d);
+ }while(d < 0 || d > 2);
+ printf("Where would you like to store the resulting matrix?\n");
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to multiply matrix %s by?\n",
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to multiply matrix %s by?\n",
- (s==0)?"A":(s==1)?"B":"C");
+ (d==0)?"A":(d==1)?"B":"C");
- matrices[s] = multiplyByN(matrices[s], n);
+ matrices[s] = multiplyByN(matrices[d], n);
- printf("What matrix would you like to fill divide by a number?\n");
+ printf("What matrix would you like to fill with a number?\n");
+ do{
+ printf("Matrix A (0), B (1) or C (2)? ");
+ scanf("%d", &d);
+ }while(d < 0 || d > 2);
+ printf("Where would you like to store the resulting matrix?\n");
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to divide matrix %s by?\n",
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to divide matrix %s by?\n",
- (s==0)?"A":(s==1)?"B":"C");
+ (d==0)?"A":(d==1)?"B":"C");
- matrices[s] = divideByN(matrices[s], n);
+ matrices[s] = divideByN(matrices[d], n);
break;
case RAISE_TO_N:
printf("What matrix would you like to raise to the power of a number?\n");
break;
case RAISE_TO_N:
printf("What matrix would you like to raise to the power of a number?\n");
+ do{
+ printf("Matrix A (0), B (1) or C (2)? ");
+ scanf("%d", &d);
+ }while(d < 0 || d > 2);
+ printf("Where would you like to store the resulting matrix?\n");
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to raise matrix %s to?\n",
do{
printf("Matrix A (0), B (1) or C (2)? ");
scanf("%d", &s);
}while(s < 0 || s > 2);
printf("With which number would you like to raise matrix %s to?\n",
- (s==0)?"A":(s==1)?"B":"C");
+ (d==0)?"A":(d==1)?"B":"C");
- matrices[s] = raiseMatrixToN(matrices[s], n);
+ matrices[s] = raiseMatrixToN(matrices[d], n);
}
return createMatrix(0, 0);
}
}
return createMatrix(0, 0);
}
// Creates a rows x columns matrix;
matrix_t createMatrix(size_t rows, size_t columns){
matrix_t newmatrix;
// Creates a rows x columns matrix;
matrix_t createMatrix(size_t rows, size_t columns){
matrix_t newmatrix;
matrix_t raiseMatrixToN(matrix_t m, int n){
if(!isSquare(m))
return matrixError(NOT_SQUARE);
matrix_t raiseMatrixToN(matrix_t m, int n){
if(!isSquare(m))
return matrixError(NOT_SQUARE);
- // TODO: only accepts positive values of n
matrix_t raisedmatrix = identityMatrix(m.rows);
matrix_t raisedmatrix = identityMatrix(m.rows);
+ if(n < 0){
+ m = inverse(m);
+ n = -n;
+ }
for(int i = 0; i < n; ++i)
raisedmatrix = multiplyMatrices(raisedmatrix, m);
return raisedmatrix;
for(int i = 0; i < n; ++i)
raisedmatrix = multiplyMatrices(raisedmatrix, m);
return raisedmatrix;
// Creates a submatrix from "matrix" without the column "column" and row "row" of "matrix"
matrix_t createSubmatrix(matrix_t m, size_t row, size_t column){
// Creates a submatrix from "matrix" without the column "column" and row "row" of "matrix"
matrix_t createSubmatrix(matrix_t m, size_t row, size_t column){
+ // TODO: not remove any
int mod = m.rows, nmod = mod-1, sr = 0, sc = 0;
matrix_t submatrix = createMatrix(nmod, nmod);
for(size_t r = 0; r < mod; ++r){
int mod = m.rows, nmod = mod-1, sr = 0, sc = 0;
matrix_t submatrix = createMatrix(nmod, nmod);
for(size_t r = 0; r < mod; ++r){
int det = determinant(m);
if(det == 0)
return matrixError(ZERO_DET);
int det = determinant(m);
if(det == 0)
return matrixError(ZERO_DET);
- return multiplyByN(adjugate(m), (float)1/det);
+ return divideByN(adjugate(m), det);
}
\ No newline at end of file
}
\ No newline at end of file