Question

Using MATLAB
15. Write a program that: a. b. c. Accept two numbers n and m in the range of 1-6 Define three arrays A, B and Cof size n by m. (n-# of rows, m-H of columns) Fill the elements of array A by A(ij)-itj i-5 d. Fill the elements of array B by B(ij)ij e. Fill the elements of array C with the average of the corresponding elements of A f. g. h. and B Print the results Find the element in array C which has the maximum value. Print the value and the location of this element.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

prompt = 'Enter n : ';

% get user input

n = input(prompt);

prompt = 'Enter m : ';

% get user input

m = input(prompt);

% create matrix of size n x m

A = zeros( n , m );

B = zeros( n , m );

C = zeros( n , m );

% fill the contents of A

for i = 1 : n

  

    for j = 1 : m

       

        A(i , j) = i + j;

       

    end

   

end

% fill the contents of B

for i = 1 : n

   

    for j = 1 : m

       

        B(i , j) = i - j;

       

    end

   

end

% fill the contents of C

for i = 1 : n

   

    for j = 1 : m

       

        C(i , j) = ( A(i , j) + B(i , j) ) / 2;

       

    end

   

end

A

B

C

% store the maximum value in C

max_val = A(1 , 1);

% store the location

max_i = 1;

max_j = 1;

% fill the contents of C

for i = 1 : n

   

    for j = 1 : m

       

        if C(i , j) > max_val

           

            max_i = i;

            max_j = j;

           

        end

       

    end

   

end

fprintf('\nMax Value in C is at position ( %d , %d )\n', max_i, max_j);

Sample Output

Enter n : 5
Enter m : 6

A =

2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
5 6 7 8 9 10
6 7 8 9 10 11


B =

0 -1 -2 -3 -4 -5
1 0 -1 -2 -3 -4
2 1 0 -1 -2 -3
3 2 1 0 -1 -2
4 3 2 1 0 -1


C =

1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4
5 5 5 5 5 5


Max Value in C is at position ( 5 , 6 )

Add a comment
Know the answer?
Add Answer to:
Using MATLAB 15. Write a program that: a. b. c. Accept two numbers n and m...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Matlab Write a program which will: a. Accept two numbers from the user m and...

    Using Matlab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Provide the user the following menu from which he can select: 1. Sum of all elements in the array. Print the result. 2. Sum of the element in a row that he’ll specify. Print the result. 3. Sum of the...

  • Write a C++ program that simulates a lottery game. Your program should use functions and arrays....

    Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...

  • write a java program Accept a positive integer n from keyboard and then create an array...

    write a java program Accept a positive integer n from keyboard and then create an array or arraylist containing n random elements within the range [-n,n). Print out the random array or arraylist, and then find out and print out the number of inversions and the maximum subarray (index range of the maximum subarray along with the maximum subarray sum) in the array or arraylist using divide and conquer, respectively. For example, suppose we accept integer 6 from keyboard, then...

  • Write a c program to implement Quicksort for arrays of length 16, as described in the...

    Write a c program to implement Quicksort for arrays of length 16, as described in the textbook, taking always as the pivot the last element of the corresponding subarray. Define a variable COUNTER in your program that keeps track of the total number of comparisons among the elements in the array needed to sort the array Run your program 100 times using as inputs 100 arrays of real numbers in the interval [0, 11 generated randomly. Find the sample average...

  • Write a c program to implement threads. Accept an array of 40 integers, write a thread...

    Write a c program to implement threads. Accept an array of 40 integers, write a thread method named sum of array elements. Divide the array into 4 equal elements and call threads to find the sum of each part. Store the sum in a variable called “arrays'. Print the sum in the main function. (10 points)

  • c++. please show screenshots of output This project will continue to familiarize the student with using...

    c++. please show screenshots of output This project will continue to familiarize the student with using arrays. Store all the function proto-types in project11_funch and store all the functions in project11_func.cpp. Make sure you have proper header comments in each.h,.cpp file. When you run your program, your sample output should show your name. Your report should include the following: 1) project11_func.h 2) project11_func.cpp 3) project11.cpp 4) sample output Write the following functions: a) void fill_array_with_random_nums(int array(), int N): Fill array...

  • C++. Write a program that copies the contents of one array into another array but in...

    C++. Write a program that copies the contents of one array into another array but in reverse order using pointers.           - in main()                    - define 2 arrays of type int, 10 elements each                              - initialize one array with numbers 1 through 10                              - initialize all elements of the second array to 0                    - call function reverseCopy with both arrays as arguments                    - display the values of array number 2 (reversed order)           - reverseCopy...

  • write a complete Java program with comments in main and in each method. Data: The input data for this program is given as two columns of numbers. All data will be entered from a fle named input.t...

    write a complete Java program with comments in main and in each method. Data: The input data for this program is given as two columns of numbers. All data will be entered from a fle named input.txt and all output will go to the screen Assume there will not be more than 100 7 23.56 16 88.12 10 75.1 Design a Java class with a main method that does the following 1) Reads the data into two arrays of doubles,...

  • Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load...

    Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load them into an array. Add up all the values and store the answer in a variable. Find the largest and smallest number in the array. Put each into its own variable. Print to the screen the sum, largest value, and smallest value. Copy the array to a second array in reverse order. Print out the second array. Read in 20 integer numbers, all in...

  • Solve using visual basic, c#, or c++ 1. Write a program to do the Gauss Elimination...

    Solve using visual basic, c#, or c++ 1. Write a program to do the Gauss Elimination procedure for a set of simultaneous linear equations. The input is a comma separated file of numbers. Write the program in the following phases. Ensure each phase runs correctly before you proceed to the next phase. a. Write a computer program to open a.csv file, and read the contents an augmented matrix of n columns and n +1 rows. The program should display the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT