Test Score relational operators MATLAB

In summary, The conversation is about a student trying to solve code problems for a class. They are having difficulty with some of the problems and are trying to understand why their code is not working for all values of a certain variable. They discuss the use of equality and inequality symbols in their code and receive a hint to think about the difference between using "any" and "all". They eventually figure out the correct code for most of the problems, except for problem 14, where they need to find the student numbers whose average score was higher than the average score of a specific student. They provide their code and ask for help in understanding why it is not working.
  • #1
gfd43tg
Gold Member
950
50

Homework Statement


Hello, I am working on problems 6-14 on the attached PDF. Don't be scared off, they are just one line of code each. I got number 6 correct, and I got partial credit on 7 and 8, but I am trying to figure out why it is not right.


Homework Equations





The Attempt at a Solution


Here is the code for 6, which is correct.
Code:
everLowest = max(Grades(sNum,:) <= min(Grades(:,:)));

7)
Code:
neverLowest = min(Grades(sNum,:) >= min(Grades(:,:)));
I run the autograder and get the error message:
Code:
Problem 7: 3/5
*the value of neverLowest is incorrect for the variables: sNum = 27; 
Incompatible logical variables
*the value of neverLowest is incorrect for the variables: sNum = 77; 
Incompatible logical variables

8)
Code:
alwaysLowest = min(Grades(sNum,:) < min(Grades(:,:)));
I get the following error for number 8
Code:
Problem 8: 4/5
*the value of alwaysLowest is incorrect for the variables: sNum = 112; 
Incompatible logical variables

So I know the autograder runs for about 5 values of sNum. My code works for some of the values of sNum, but not all. I don't understand why these codes are not valid for all values of sNum?

This is my english translation of the code, I want to know if I am understanding this correctly. I will use #6 as my example since I got full credit for that problem.
Code:
everLowest = max(Grades(sNum,:) <= min(Grades(:,:)));
means the maximum grade of a particular student (sNum) on every exam (:) is less than or equal to the minimum grade of all other students on all other exams (min(Grades(:,:)).

Edit: Apparently the answer lies in the fact that I needed to change the >= to > for (7), and < to <= for (8), but I don't see exactly why. The signs are confusing the heck out of me

Here are the new correct answers
Code:
7) neverLowest = min(Grades(sNum,:) > min(Grades(:,:)));
8) alwaysLowest = min(Grades(sNum,:) <= min(Grades(:,:)));
9) everHighest = max(Grades(sNum,:) >= max(Grades(:,:)));

And here is (10)
Code:
neverHighest = max(Grades(sNum,:) <= max(Grades(:,:)));
Problem 10: 4/5
*the value of neverHighest is incorrect for the variables: sNum = 18; 
Incompatible logical variables
It's now at the point where I am just switching mins, max, and the direction of the inequality symbol as well as tacking on an = until I get it right. I am missing something fundamental and must not be comprehending the questions correctly. Ideally I should be able to read the question and know which way to put the signs and whether or not to have an equal in the inequality (choosing between ≤ or <, etc)
 

Attachments

  • REL test grades.pdf
    22.5 KB · Views: 241
Last edited:
Physics news on Phys.org
  • #2
For 7, the opposite of "less than or equal" is not "greater than or equal". Alternatively, find out how to say "not" directly in Matlab.

For 8, compare questions between 6 and 8. The only difference is the word "any" in 6 and "all" in 8. Think about what that difference means, if student snum scored say 10, 25, 30 on 3 tests, and another student scored 15, 20, 25.
 
  • #3
That is so confusing to me. How is the opposite of ''less than or equal'' not ''greater than or equal''?

For 7, if I just add the not to 6, it gets it wrong.

Code:
neverLowest = min(Grades(sNum,:) ~<= min(Grades(:,:)));

Apparently ~<= is not equivalent to ''not less than or equal to'', so then what is??
 
Last edited:
  • #4
5 is less than or equal to 6
6 is less than or EQUAL to 6
6 is greater than or EQUAL to 6
6 is NOT greater than 6

if that makes sense :)
 
  • #5
Sorry, cpscdave, I don't get the hint =(
 
  • #6
The opposite of Less than or equal would be strictly greater than :) The counter example being 6
as both
6<=6 and 6>=6 are true, which implies that the <= and >= operators are not opposite of one another
 
  • #7
Why is it for 7 I get full credit, but 10 only 4/5 points?

Code:
neverLowest = min(Grades(sNum,:) > min(Grades(:,:)));
neverHighest = max(Grades(sNum,:) < max(Grades(:,:)));

Also Dave, now I get what you were saying. That is good to know
 
Last edited:
  • #8
Okay, the only one I am stuck on now is number 14

Assign to the variable curveBusters an S-by-1 array (S may be 0) of the student numbers whose
average score (across all tests) was strictly higher than average score of the student indicated by
sNum.

here is my code

Code:
S = 0;
curveBusters = find(mean(Grades(sNum,:)) < mean(Grades(:,:)));

I have to find the students who had a higher average score that sNum across all tests, but this is not the right code. My code should be finding the mean of the student sNum across all exams, then the mean of all students across all exams, and whoever has a higher overall mean than sNum is what should show. That is what I intend this code to do, but I can't tell why it is not working.
 
Last edited:

What are test score relational operators in MATLAB?

Test score relational operators in MATLAB are used to compare numerical values in order to determine their relationship. These operators include <, >, <=, >=, ==, and ~=, which respectively stand for less than, greater than, less than or equal to, greater than or equal to, equal to, and not equal to.

How do I use test score relational operators in MATLAB?

To use test score relational operators in MATLAB, you would first need to have numerical values to compare. Then, you can use the desired operator to compare the values and the result will be a logical value (either true or false) indicating the relationship between the two values.

Can I use test score relational operators with non-numerical values in MATLAB?

No, test score relational operators in MATLAB can only be used with numerical values. If you want to compare non-numerical values, you would need to convert them to numerical values first.

What happens when I use multiple test score relational operators in one statement in MATLAB?

When multiple test score relational operators are used in one statement in MATLAB, the operators are evaluated from left to right. If the first comparison is true, the statement will continue to evaluate the next comparison. However, if the first comparison is false, the statement will stop evaluating and return a logical false value.

Are there any other types of relational operators in MATLAB?

Yes, besides test score relational operators, there are also logical relational operators in MATLAB. These include && (AND), || (OR), and ~ (NOT). These operators are used to evaluate logical expressions and return logical values.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
324
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top