added scalar matrix multiplication

This commit is contained in:
superdimensional 2021-04-18 22:28:42 -04:00
parent fc1d949919
commit 581ea39bbd
3 changed files with 131 additions and 32 deletions

3
.gitignore vendored
View file

@ -50,3 +50,6 @@ modules.order
Module.symvers Module.symvers
Mkfile.old Mkfile.old
dkms.conf dkms.conf
# random shit I test
test.c

View file

@ -1,65 +1,121 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
double exponent( double par){ double exponent(double par)
{
double raisedNum; double raisedNum;
raisedNum = par * par; raisedNum = par * par;
return raisedNum; return raisedNum;
}; };
double hypotenuse(double par, double par2){ double hypotenuse(double par, double par2)
{
double sideC; double sideC;
sideC = sqrt( exponent(par) + exponent(par2) ); sideC = sqrt(exponent(par) + exponent(par2));
return sideC; return sideC;
}; };
void quadratic(double numA, double numB, double numC, double *awn1ptr, double *awn2ptr){ void quadratic(double numA, double numB, double numC, double *awn1ptr, double *awn2ptr)
{
double awn1 = (-numB) + sqrt( exponent(numB) - 4 * numA * numC);
double awn1 = (-numB) + sqrt(exponent(numB) - 4 * numA * numC);
double awn1F = awn1 / (2 * numA); double awn1F = awn1 / (2 * numA);
double awn2 = (-numB) - sqrt( exponent(numB) - 4 * numA * numC); double awn2 = (-numB) - sqrt(exponent(numB) - 4 * numA * numC);
double awn2F = awn2 / (2 * numA); double awn2F = awn2 / (2 * numA);
*awn1ptr = awn1F; *awn1ptr = awn1F;
*awn2ptr = awn2F; *awn2ptr = awn2F;
}; };
double areaOfCircle(double radius){ double areaOfCircle(double radius)
{
double area; double area;
area = acos(-1) * exponent(radius); area = acos(-1) * exponent(radius);
return area; return area;
} }
int buildMatrix(int numRows, int numColumns) // int buildMatrix(int numRows, int numColumns)
// {
// int matrix[numRows][numColumns];
// printf("\nEnter elements in matrix of size %dx%d \n", numRows, numColumns);
// for (int i = 0; i < numRows; i++)
// {
// for (int j = 0; j < numColumns; j++)
// {
// scanf("%d", &matrix[i][j]);
// }
// }
// printf("\nElements in matrix are: \n");
// for (int i = 0; i < numRows; i++)
// {
// for (int j = 0; j < numColumns; j++)
// {
// printf("%d ", matrix[i][j]);
// }
// printf("\n");
// }
// return 0;
// }
//TODO: rewrite matrix builder
void printMatrix(int row, int col, int m[row][col])
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
printf("%d ", m[row][col]);
}
printf("\n");
}
return;
}
void addMatrices(int r, int c, int m1[r][c], int m2[r][c], int mr[r][c])
{
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
mr[i][j] = m1[i][j] + m2[i][j];
}
}
}
int scalarMultiplication(int numRows, int numColumns, int scalar)
{ {
int matrix[numRows][numColumns]; int matrix[numRows][numColumns];
printf("\nEnter elements in matrix of size %dx%d \n", numRows, numColumns); printf("\nEnter elements in matrix of size %dx%d \n", numRows, numColumns);
for(int i = 0; i < numRows; i++) for (int i = 0; i < numRows; i++)
{ {
for(int j = 0; j < numColumns; j++) for (int j = 0; j < numColumns; j++)
{ {
scanf("%d", &matrix[i][j]); scanf("%d", &matrix[i][j]);
} }
} }
printf("\nElements in matrix are: \n"); printf("\nScaled matrix is: \n");
for(int i = 0; i < numRows; i++) for (int i = 0; i < numRows; i++)
{ {
for(int j = 0; j < numColumns; j++) for (int j = 0; j < numColumns; j++)
{ {
printf("%d ", matrix[i][j]); printf("%d ", matrix[i][j]*scalar);
} }
printf("\n"); printf("\n");
} }
return 0;
}
return 0;
}

60
main.c
View file

@ -15,6 +15,8 @@ int main()
printf("\n 4. Build a matrix"); printf("\n 4. Build a matrix");
printf("\n 5. Matrix determinant"); printf("\n 5. Matrix determinant");
printf("\n 6. Matrix addition"); printf("\n 6. Matrix addition");
printf("\n 7. Matrix multiplication");
printf("\n 8. Scalar matrix multiplication");
printf("\n\n Enter your choice here:_____"); printf("\n\n Enter your choice here:_____");
printf("\033[D"); printf("\033[D");
printf("\033[D"); printf("\033[D");
@ -80,22 +82,22 @@ int main()
case 4: case 4:
system("clear"); system("clear");
printf("\n ~~ Build a matrix ~~\n\n"); // printf("\n ~~ Build a matrix ~~\n\n");
int numRows; // int numRows;
int numColumns; // int numColumns;
printf("\nPlease enter the number of rows: "); // printf("\nPlease enter the number of rows: ");
scanf("%d", &numRows); // scanf("%d", &numRows);
printf("\nPlease enter the number of columns: "); // printf("\nPlease enter the number of columns: ");
scanf("%d", &numColumns); // scanf("%d", &numColumns);
buildMatrix(numRows, numColumns); // buildMatrix(numRows, numColumns);
break; break;
//TODO: replace this
case 5: case 5:
system("clear"); system("clear");
printf("\n ~~ Matrix determinant ~~\n\n"); printf("\n ~~ Matrix determinant ~~\n\n");
break; break;
@ -103,7 +105,45 @@ int main()
system("clear"); system("clear");
printf("\n ~~ Matrix addition ~~\n\n"); printf("\n ~~ Matrix addition ~~\n\n");
// int numRows;
// int numColumns;
// printf("\nPlease enter the number of rows: ");
// scanf("%d", &numRows);
// printf("\nPlease enter the number of columns: ");
// scanf("%d", &numColumns);
// printMatrix(numRows, numColumns, matrix1);
// printf("\n");
// printMatrix(numRows, numColumns, matrix2);
// printf("\n");
// addMatrices(numRows, numColumns, matrix1, matrix2, sumMatrix);
// printMatrix(numRows, numColumns, sumMatrix);
break;
case 7:
system("clear");
printf("\n ~~ Matrix multiplication ~~\n\n");
break;
case 8:
system("clear");
printf("\n ~~ Scalar matrix multiplication ~~\n\n");
int numRows;
int numColumns;
int scalar;
printf("\nPlease enter the number of rows: ");
scanf("%d", &numRows);
printf("\nPlease enter the number of columns: ");
scanf("%d", &numColumns);
printf("\nPlease enter the scalar multiplier: ");
scanf("%d", &scalar);
scalarMultiplication(numRows, numColumns, scalar);
break; break;