Last edited by a moderator: May 5, 2017

So, by creating a matrix with an index, I assume you mean set values to the indices of the matrix. So as a first try, let's say you have a 3x3 matrix, what does the for loop look like here?In summary, the functions maxEntry and totalSum require the use of array indexing and looping in order to complete them without using built-in functions. The first function, maxEntry, requires the use of two indices, p and q, which must satisfy the property that |A(p,q)|>=|A(i,j)| for all i and j in the range of 1 to m and 1 to n respectively. The second function, totalSum, simply requires the sum of all
  • #1
nothingatall
19
0
1) function [p,q] = maxEntry(A)
% A is an m-by-n matrix.
%p and q are indices with the property that |A(p,q)|>=|A(i,j)|
% for all i and j that satisfy 1<=i<=m, 1<=j<=n.

2) function s = totalSum(A)
% A is an m-by-n matrix
% s is the sum of all the values in A

complete them without using built in functions.

3) I've tried to look these up on help but these are not helping. I've tried to create the matrix with an index but this is not working. I think i know how to do a for loop but should i know anything when referring to the function at hand??

Thanks
 
Physics news on Phys.org
  • #2
These sound like homework, so perhaps a mod will be by to relocate this thread.

Both of these questions are intended to get you familiar with MATLAB's array indexing and looping. If you're not familiar with array indexing, the help documentation is quite helpful:
http://www.mathworks.com/help/techdoc/math/f1-85462.html

Having said that, for at least the summation problem, it's possible to avoid the indexing by using linear indexing instead of (row, column) type indexing. But since you still need it for the first, let's go with that.

Now, as for how to do looping, here's the Mathworks documentation page on various Program Control methods:
http://www.mathworks.com/help/techdoc/matlab_prog/brqy1c1-1.html

If you're new to programming, my advice is to first come up with the algorithm / pseudocode before the specific implementation. Do this here and we'll try to help you along.
 
Last edited by a moderator:

What is the "max entry" in Matlab?

In Matlab, the "max entry" refers to the largest value in a given array or matrix.

How can I find the maximum value in an array using Matlab?

To find the maximum value in an array, you can use the "max" function in Matlab. This function returns the highest value in the array along with its corresponding index.

What is the "total sum" in Matlab?

The "total sum" in Matlab refers to the sum of all the elements in a given array or matrix.

How do I calculate the total sum of an array in Matlab?

To calculate the total sum of an array in Matlab, you can use the "sum" function. This function adds up all the elements in the array and returns the total sum.

What happens if there are negative values in the array when finding the maximum or total sum in Matlab?

When finding the maximum or total sum in Matlab, negative values are also considered and included in the calculation. However, if you only want to consider positive values, you can use the "max" or "sum" function with the "abs" function to find the maximum or total sum of the absolute values in the array.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
801
  • Engineering and Comp Sci Homework Help
Replies
1
Views
930
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
Back
Top