Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Euclidian norm of a matrix it the squareroot of the square sum of all its el

ID: 3581677 • Letter: T

Question

The Euclidian norm of a matrix it the squareroot of the square sum of all its elements. For example the Euclidian norm of the following matrix: (4 8 -2 6 -3 2 4-1 1 5 3 2)is squareroot 16 + 9 + 1+ 64 + 4 + 25 + 4 + 16 + 9 + 36 + 1 + 4 = 13.747727 Based on the above and after studying main() -below-, write the following functions: input () to prompt the user to enter the number of rows and number of columns of a matrix, respectively The function then reads all elements of the matrix. print () to print the matrix. EuclidianNorm() to compute and return the Euclidian norm of the matrix. Use this main() function as is: int main () {const int ROWS = 10; const int COLS = 10; int r, c; double result, A[ROWS] [COLS]; input (r, c, A); result = EuclidianNorm(r, c, A); Print (result, r, c, A); return 0;}

Explanation / Answer

#include<stdio.h>
#include<math.h>

const int ROWS = 10;
const int COLS = 10;
int main()
{
  
   int r, c;
   double result, A[ROWS][COLS];
   void input(int *r, int *c, double A[][COLS]);
   void print(double result, int r, int c, double A[][COLS]);
   double EueldianNorm(int r, int c, double A[][COLS]);

   input(&r, &c, A);
   result = EueldianNorm(r, c, A);
   print(result, r, c, A);
   return 0;
}

void input(int *r, int *c, double A[][COLS])
{
   int i, j;
   printf("Enter number of rows = ");
   scanf("%d", r);
   printf( "Enter number of columns = ");
   scanf("%d", c);
   printf( "Enter Matrix elements : " );
   for (i = 0; i < *r; i++)
   {
       for (j = 0; j < *c; j++)
       {
           printf("A[%d][%d] = ", i, j);
           scanf("%lf", &A[i][j]);
       }
   }
}

void print(double result, int r, int c, double A[][COLS])
{
   int i, j;
   printf(" Elements of matrix are : ");
   for (i = 0; i < r; i++)
   {
       for (j = 0; j < c; j++)
       {
           printf("%.2lf ", A[i][j]);
       }
       printf(" ");
   }
   printf("result = %lf ", result);
}

double EueldianNorm(int r, int c, double A[][COLS])
{
   double sum = 0;
   int i, j;

   for (i = 0; i < r; i++)
   {
       for (j = 0; j < c; j++)
       {
           sum += A[i][j] * A[i][j];
       }
   }

   sum = sqrt(sum);
   return sum;
}

---------------------------------------------------------------------------------------------------------------

output

Enter number of rows = 3
Enter number of columns = 4
Enter Matrix elements :
A[0][0] = 4
A[0][1] = 8
A[0][2] = -2
A[0][3] = 6
A[1][0] = -3
A[1][1] = 2
A[1][2] = 4
A[1][3] = -1
A[2][0] = 1
A[2][1] = 5
A[2][2] = 3
A[2][3] = 2

Elements of matrix are :
4.00 8.00 -2.00 6.00
-3.00 2.00 4.00 -1.00
1.00 5.00 3.00 2.00
result = 13.747727

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote