Question

Matlab Queatoin: The test suite generates a random M x N matrix with a random number...

Matlab Queatoin: The test suite generates a random M x N matrix with a random number of rows and columns that is assigned to the variable A . The element values of the matrix are random double precision numbers that fall in the range from -10 to 10. The matrix has between 5 and 10 rows and between 5 and 10 columns. Assuming A is defined in the workspace, write a script with commands to perform the operations described below and assign the results to the indicated variable names.

Create a new 2 x N matrix, B, that consists of the first and last rows of A.

Create a new 2 x 2 matrix, C, that consists of the elements at the four corners of A.

Create a new M-1 x N-1 matrix, D, that consists of the second through last columns in the second through last rows of A.

Here is the question reamind" %Enter the commands for your script mfile here. Be sure to assign the matrices specified in the problem statement to the indicated variable names.

B = A;
C = A;
D = A;"

Homework Answers

Answer #1

Solution for problem( C programming)

Program :-

#include<stdio.h>
int main()
{
int A[100][100],B[100][100],C[100][100],D[100][100],i,j,rows,columns,k=0,l=0,m=0,n=0,o=0,p=0;
printf("Enter number of Rows (between 5 to 10) :-");
scanf("%d",&rows);
printf("Enter number of Columns (between 5 to 10) :-");
scanf("%d",&columns);
printf("Enter values into Matrix A :-\n");
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
scanf("%d",&A[i][j]);
}
}
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
if(i==0 || i==rows-1) //Creating B matrix.
{
B[o][p++]=A[i][j];
if(p>columns-1)
{
o++;
p=0;
}
}
if((i==0 && j==0) || (i==0 && j==columns-1) || (i==rows-1 && j==0) || (i==rows-1 && j==columns-1)) //Creating C matrix.
{
C[k][l++]=A[i][j];
if(l>1)
{
k++;
l=0;
}

}
if(i>0 && j>0) // Create D matrix.
{
D[m][n++]=A[i][j];
if(n==columns-1)
{
m++;
n=0;
}

}

}
}
printf("Matrix B is :-\n");
for(i=0;i<2;i++)
{
for(j=0;j<columns;j++)
{
printf("%d\t",B[i][j]);
}
printf("\n");
}
printf("\nMatrix C is :-\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",C[i][j]);
}
printf("\n");
}
printf("\nMatrix D is :-\n");
for(i=0;i<rows-1;i++)
{
for(j=0;j<columns-1;j++)
{
printf("%d\t",D[i][j]);
}
printf("\n");
}
return 0;
}

Output :-

Enter number of Rows (between 5 to 10) :-4
Enter number of Columns (between 5 to 10) :-5
Enter values into Matrix A :-
1 2 3 4 5
11 12 13 14 15
21 22 23 24 25
31 32 33 34 35
Matrix B is :-
1 2 3 4 5
31 32 33 34 35

Matrix C is :-
1 5
31 35

Matrix D is :-
12 13 14 15
22 23 24 25
32 33 34 35

Note :- All B,C,D matrices are priented separetly.

Thank you!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Code a program to reproduce Madame Esmerelda’s clairvoyant test: Mme. Esmerelda conjures up a random number...
Code a program to reproduce Madame Esmerelda’s clairvoyant test: Mme. Esmerelda conjures up a random number 1-10 in her mind and commands the user to guess what it is. If the user’s guess is equal to (remember your double equal sign!) the conjured number, Mme. Esmerelda extends a job offer as a clairvoyant assistant. Add a user-driven loop that allows the user to play repeatedly if desired (but your program should conjure a new random number with every loop iteration)....
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS = 5000 # generates a random n-queens board # representation: a list of length n the value at index i is # row that contains the ith queen; # exampe for 4-queens: [0,2,0,3] means that the queen in column 0 is # sitting in row 0, the queen in colum 1 is in row, the queen in column 2 # is in row 0,...
1.A fair die is rolled once, and the number score is noted. Let the random variable...
1.A fair die is rolled once, and the number score is noted. Let the random variable X be twice this score. Define the variable Y to be zero if an odd number appears and X otherwise. By finding the probability mass function in each case, find the expectation of the following random variables: Please answer to 3 decimal places. Part a)X Part b)Y Part c)X+Y Part d)XY ——- 2.To examine the effectiveness of its four annual advertising promotions, a mail...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT