Question

1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name the function [max_value, max_inde

matlab

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

function [max_value,max_index]=LASTNAMES_matrix_max(x)
%[max_value,max_index]=LASTNAMES_matrix_max(x)
%This function returns the maximum value in a vector or matrix, and the
%index at which the value is
%INPUTS:
%x = A numerical vector/matrix
%OUTPUTS:
%max_value = maximum value in x
%max_index = index of max_value
if isscalar(x)
error('Input must be a matrix or vector!!')
elseif ~isnumeric(x)
error('Input must be a numeric matrix or vector!!!')
else
max_value=x(1,1);
max_index=[1,1];
for i=1:size(x,1)
for j=1:size(x,2)
if x(i,j)>max_value
max_value=x(i,j);
max_index=[i,j];
end
end
end
if size(x,1)==1
max_index=max_index(2);
elseif size(x,2)==1
max_index=max_index(1);
end
end

Command Window - O X Editor - C:\Users\Vaibhav\Documents\MATLAB2\LASTNAMES_matrix_max.m - 0 >> help LASTNAMES_matrix_max [max

Add a comment
Know the answer?
Add Answer to:
matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name...
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
  • 1. Write a MATLAB function that takes a matrix, a row number and a scalar as...

    1. Write a MATLAB function that takes a matrix, a row number and a scalar as arguments and multiplies each element of the row of the matrix by the scalar returning the updated matrix. 2. Write a MATLAB function that takes a matrix, two row numbers and a scalar as arguments and returns a matrix with a linear combination of the rows. For example, if the rows passed to the function were i and j and the scalar was m,...

  • Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following...

    Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following math function with x the input argument and y the output y(x)=0.8x4-13x2-5x The function should work for x being a scalar or a vector. Write a script file named PBTask4pl.m to a) Use the function to calculate y(3) and y(5) and display the results in command window b) Use the function to make a plot of the function y(x) for -5:5: x 5:5. Label...

  • in MATLAB 3. Write a function called gauss_seidel that inputs an n x n matrix, A,...

    in MATLAB 3. Write a function called gauss_seidel that inputs an n x n matrix, A, a column vector, b, an initial guess xo), an error tolerance e, and a maximum number of iterations, and output an approximate solution obtained using the Gauss-Seidel method, the error and the number of iterations. The header should look like (x, err, N] = gauss_seidel (A, b, x0, tol, Nmax). Use the method to find approximate solutions to the linear system -2 1 0...

  • [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a...

    [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a vector. The cumulative product, pj, of the jth element of the vector x, xj, is defined by pj = (x1)(x2) … (xj) for j = 1:length of the vector x. DO NOT USE CUMPROD For example, when you run your function it should look like this: >> x = [2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,...

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