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

please help, the answers should be given im matlab code will rate Instructions:

ID: 3195144 • Letter: P

Question

please help, the answers should be given im matlab code
will rate

Instructions: For the following exercise and the output obtained by running the and into a text document the function M-files 4. The product y = Ax of an m × n matrix A times a vector x = (r , zn)T can be computed 2, w-ise as that is Write a function M-file that takes as input matrix A and n vector x, and as output gives the product yAx by rou, as defined above (Hint: use a for loop to define each entry of the vector Your M-file should perform a check on the dimensions of the input variables A and x and return a message if the dimensions do not match. Cal the file nyrowproduct.m. Note that this file will NOT be the same as the myproduct.m M-file example. Test your function on n random 2 × 3 matrix A and random 3 × 1 vector x. Compare the output with Aex Repeat with 3 × 4 matrix and a 4 x 1 vector ard with 3 × 4 matrix ard a 1 × 4 vector Include in your lab report the function M-file and the output obtained by running it 5. Recall that if A is an m × n matrix and B is a p x q matrix, then the product C = AB is defined if and only if = p, in which case C is an m × q matrix. (a) Write a function M-file that takes as input two matrices A and B, and as output produces the product by colmns of the two matrix For instance, if A is 3 × 4·and B is 4 × 5, the product is given by the matrix The function file should work for any dimension of A and B and it should perforn a check to see if the dimensions match (Hint: use a for loop to define the columns of C). Call the fle col unnproduct·n. Test your function on a random 2 × 3 matrix A and a random 3 x 2 matrix B . Compare the output with A*B. Repeat with 3 x 4 and 4 x 2 matrices and with 3 4 and 2 × 4 matrices. Include in yur lab report the function M-ile and the output obtained by running it (b) Write a function M-file that takes as input two matrices A and B, and as output produces the product by rows of the two matrices For instance, if A is 3 × 4 and B is 4 × 5, the product AB is given by the matrix The function file should work for any dimension of A and B and it should perform a check to see if the dimensions match (Hint: use /1 for loop to define the rows of C). Call the file rowproduct.m Test your function on a random 2 × 3 matrix A and a ranolom 3 x 2 matrix B . Compare the output with A*B. Repeat with 3 × 4 and 4 × 2 matrices and with 3 × 4 and 2 × 4 matrices. Include in your lab report the function M-file and the output obtained by running it

Explanation / Answer

#include<stdio.h>
void main(){
int m,n,k,l,i,j,sum=0,p;           //m,n represents order of A i.e., mxn
scanf("%d %d %d %d",&m,&n,&k,&l);
int A[m][n],X[k][l],M[m][l];        //A is the matrix and X is a vector and M is the resultant matrix
if(n!=k){
printf("unable to process multiplication ");
return 0;
}
else{
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&A[i][j]);
}
}
for(i=0;i<k;i++){
for(j=0;j<l;j++){
scanf("%d",&X[i][j]);
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
M[i][j]=0;
}
}
for (i = 0; i < m; i++) {
      for (j = 0; j < l; j++) {
        for (p = 0; p < n; p++) {
          sum = sum + A[i][p]*X[p][j];
        }

        M[i][j] = sum;
        sum = 0;
      }
    }
for(i=0;i<m;i++){
for(j=0;j<l;j++){
printf("%d ",M[i][j]);
}
}
}
}


/* examples
1.A is of order 2x3 with elements [1 2 3]
                                  [4 5 6]
X is of 3x1 with elements [1]
                           [2]
                           [3]
M is of order 2x1 with elemets [14]
                                [32]
2.A is of order 3x4 with elements [1 2 3 4]
                                  [1 2 3 4]
                                  [1 2 3 4]
X is of 4x1 with elements [1]
                           [2]
                           [3]
                           [4]
     M is [30]
          [30]
          [30]                                                          
*/

#include<stdio.h>
void main(){
int m,n,k,l,i,j,sum=0,p;           //m,n represents order of A i.e., mxn
scanf("%d %d %d %d",&m,&n,&k,&l);
int A[m][n],X[k][l],M[m][l];        //A is the matrix and X is a vector and M is the resultant matrix
if(n!=k){
printf("unable to process multiplication ");
return 0;
}
else{
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&A[i][j]);
}
}
for(i=0;i<k;i++){
for(j=0;j<l;j++){
scanf("%d",&X[i][j]);
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
M[i][j]=0;
}
}
for (i = 0; i < l; i++) {
      for (j = 0; j < m; j++) {
        for (p = 0; p < n; p++) {
          sum = sum + A[j][p]*X[p][i];
    //printf("%d ",sum);
        }

        M[j][i] = sum;
        sum = 0;
      }
    }
for(i=0;i<m;i++){
for(j=0;j<l;j++){
printf("%d ",M[i][j]);
}
printf(" ");
}
}
}

#include<stdio.h>
void main(){
int m,n,k,l,i,j,sum=0,p;           //m,n represents order of A i.e., mxn
scanf("%d %d %d %d",&m,&n,&k,&l);
int A[m][n],X[k][l],M[m][l];        //A is the matrix and X is a vector and M is the resultant matrix
if(n!=k){
printf("unable to process multiplication ");
return 0;
}
else{
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&A[i][j]);
}
}
for(i=0;i<k;i++){
for(j=0;j<l;j++){
scanf("%d",&X[i][j]);
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
M[i][j]=0;
}
}
for (i = 0; i < m; i++) {
      for (j = 0; j < l; j++) {
        for (p = 0; p < n; p++) {
          sum = sum + A[i][p]*X[p][j];
        }

        M[i][j] = sum;
        sum = 0;
      }
    }
for(i=0;i<m;i++){
for(j=0;j<l;j++){
printf("%d ",M[i][j]);
}
}
}
}