Question

In: Computer Science

MATLAB: Write a function called problem2 that takes an at most two-dimensional matrix A as its...

MATLAB:

Write a function called problem2 that takes an at most two-dimensional matrix A as its sole input. The function uses a while-loop to return the largest element of A. You are not allowed to use the built-in max function and you are also not allowed to use for-loops.

Solutions

Expert Solution

problem2.m

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

function [max] = problem2(arr)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%row have no of row of entered matrix
%col have no of column of entered matrix
[row,col]=size(arr);
i=1; % i for row index
% max contain 1st element of 2d matrix
max=arr(1,1);

while i<=row
j=1; % j for column index
while j<=col
if (arr(i,j)>max)
max=arr(i,j);

end
j=j+1; % increment for column
end
i=i+1; % incremnet for row
end

end

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

Output of 2 sample input


Related Solutions

MATLAB: Write a function called max_number that takes an at most two-dimensional matrix A as its...
MATLAB: Write a function called max_number that takes an at most two-dimensional matrix A as its sole input. The function returns the largest element of A. You are not allowed to use the built-in max function.
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
Write a C++ function that takes a two dimensional dynamic array (matrix) and its sizes and...
Write a C++ function that takes a two dimensional dynamic array (matrix) and its sizes and returns true if the matrix is an upper matrix and returns false otherwise. Remark: A matrix M is an upper matrix if it is a square matrix (row size = column size) and every element M[i][j] = 0 for all i > j. That is all the elements of the matrix below the main diagonal are zero.
Write a Matlab function for a matrix that takes in a matrix in echelon form and...
Write a Matlab function for a matrix that takes in a matrix in echelon form and will return the row canonical form. The function cannot use rref, or any other matlab built in functions.
B. Write a function in MATLAB called findInverseOf2x2Matrix that takes in as input any square matrix...
B. Write a function in MATLAB called findInverseOf2x2Matrix that takes in as input any square matrix of size 2 × 2 and returns back the inverse of that matrix if one exists. If no inverse exists, print back a suitable error message. You can safely assume that we will test your code on square matrices of size 2 × 2 only. You can always verify your answer by using the inbuilt inverse function in MATLAB, however, you cannot use the...
MATLAB Function: (Backward substitution) Write a function that takes an upper triangular matrix U, and a...
MATLAB Function: (Backward substitution) Write a function that takes an upper triangular matrix U, and a vector b as input and returns the solution of the linear system U x = b. Use this function in the case when U is made of the numbers [(3,2,1),(0,5,4),(0,0,6)], and b = [1,1,−6]^T.
Write a Matlab function called “SimpleChannel” which takes a signal as an input, simulates a channel...
Write a Matlab function called “SimpleChannel” which takes a signal as an input, simulates a channel and returns the transmitted signal.. SimpleChannel function will add a randomly generated noise (look for “rand” function) to the signal and return it. You can adjust the amplitude of the noise as you want in order to have a distinct noise effect. Then write another matlab code to show the channel noise. First create the signal and then simulate the channel by using your...
C++ write a function called divideBy that takes two integers as its input and returns the...
C++ write a function called divideBy that takes two integers as its input and returns the remainder. If the divisor is 0, the function should return -1, else it should return the remainder to the calling function.
Write a function to solve the two-dimensional in Matlab, unsteady heat conduction equation with no internal...
Write a function to solve the two-dimensional in Matlab, unsteady heat conduction equation with no internal heat generation on a square domain. The length of each side of the square is 1 m. The function will have the following 4 inputs: npts                     number of grid points in each coordinate direction nt                         number of time steps to take dt                         size of time step (s) alpha                   thermal diffusivity (m2/s) Use the following initial and boundary conditions: Initialize the body to T =...
JavaScript Write a function called "first" that takes in two arguments - the first is an...
JavaScript Write a function called "first" that takes in two arguments - the first is an argument called arr that is an array of numbers, the second is an optional number argument called num(hint: you'll need a default value - look back at the slides). If "num" was not passed in (since it's optional), the "first" function will return an array containing the first item of the array. If a value for "num" was given, the "first" function will return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT