What Does the MATLAB Operator <~ Do?

In summary: I still have a concern about the 3rd element in the answer that the OP posted.In summary, the OP has a problem determining z=y<~x, where y=[-5,-2,0,3,4,10]. They are not able to find a solution using the ~ operator, and are looking for help. When they enter x into MATLAB, it returns z=[1,1,1,0,0,0], which does not seem to match the problem. They are wondering if they are supposed to determine y values that are not less than x. My guess is that they are supposed to use the < operator, which would switch the signs of each element of z.
  • #1
Eastonc2
20
0

Homework Statement


I have a problem with vectors x and y, where x=[-3,0,0,2,5,8] and y=[-5,-2,0,3,4,10]
The problem asks me to determine z=y<~x
I've searched my book and cannot determine what this operator is telling me to do. Am I supposed to determine the values of y that are not less than x? I enter this exactly as stated into MATLAB and it returns a vector z=[1,1,1,0,0,0] If someone could help me out here, i'd appreciate it.

Homework Equations




The Attempt at a Solution

 
Physics news on Phys.org
  • #2
Eastonc2 said:

Homework Statement


I have a problem with vectors x and y, where x=[-3,0,0,2,5,8] and y=[-5,-2,0,3,4,10]
The problem asks me to determine z=y<~x
I've searched my book and cannot determine what this operator is telling me to do. Am I supposed to determine the values of y that are not less than x? I enter this exactly as stated into MATLAB and it returns a vector z=[1,1,1,0,0,0] If someone could help me out here, i'd appreciate it.

Homework Equations




The Attempt at a Solution

~x is the complement of vector x, which evaluates to a new vector with all the signs switched.

z = y < ~ x causes each element of z to be set to 0 or 1 if an element of y is less than the corresponding element in ~x.

From you answer, I'm guessing that the problem is actually z = y <= ~x.
 
  • #3
Mark44 said:
~x is the complement of vector x, which evaluates to a new vector with all the signs switched.

That's not what the ~ operator does in MATLAB. The ~ is for logical negation, which only applies to logical arrays. Any true element becomes a false element and vice versa. If x is not a logical array, I believe it is first converted into one before the negation is applied. Thus "~x" will have a 0 for every non-zero element in x, and a 1 for every element of x equal to zero.

The idea of using the < operator on a logical array seems improper to me.
 
  • #4
MisterX said:
That's not what the ~ operator does in MATLAB. The ~ is for logical negation, which only applies to logical arrays. Any true element becomes a false element and vice versa. If x is not a logical array, I believe it is first converted into one before the negation is applied. Thus "~x" will have a 0 for every non-zero element in x, and a 1 for every element of x equal to zero.
Your explanation sounds reasonable to me.
MisterX said:
The idea of using the < operator on a logical array seems improper to me.
Not to me. You should be able to compare (<, <=, ==, >=, >) two logical values or two arrays of logical values.

In the OP's question, [-5, -2, 0, 3, 4, 10] is being compared to ~x = ~[-3, 0, 0, 2, 5, 8]. Each nonzero entry in ~x is replaced by 1, and each zero entry is replaced by 0, I believe. Then the two arrays are compared, element by element, with the result array having a 1 where y(i) < ~x(i), and a 0 otherwise. That's my best guess, at any rate.

I still have a concern about the 3rd element in the answer that the OP posted. I still believe that in the original problem, the comparison is <=, not <.
 
  • #5


The operator <~ in this context is known as the "not less than" operator. It is used to compare two vectors or arrays and returns a logical vector with 1s for elements that are not less than the corresponding elements in the other vector, and 0s for elements that are less than. In this case, the vector z represents the elements of y that are not less than the corresponding elements in x. So z=[1,1,1,0,0,0] means that for the first three elements, y is not less than x, while for the last three elements, y is less than x. This operator can be useful in various data analysis and sorting applications.
 

What is a "Matlab operator"?

A Matlab operator is a symbol or keyword used in the Matlab programming language to perform specific mathematical or logical operations on variables or arrays. Examples of Matlab operators include addition (+), subtraction (-), multiplication (*), division (/), and logical operators such as "and" (&&) and "or" (||).

What is the difference between a "Matlab operator" and a "Matlab function"?

A Matlab operator is a symbol or keyword used to perform mathematical or logical operations on variables or arrays, while a Matlab function is a block of code that performs a specific task. Operators are used within expressions to manipulate data, while functions are called by name to perform a specific action or calculation.

How do I use a "Matlab operator" in my code?

To use a Matlab operator in your code, you must first understand its purpose and syntax. Most operators are used within expressions, which are combinations of variables, constants, and other operators. For example, to add two numbers together, you would use the addition operator (+) between the numbers.

Can I create my own "Matlab operator"?

No, it is not possible to create custom operators in Matlab. However, you can create your own functions to perform specific tasks and call them by name in your code.

Are there any rules for using "Matlab operators" in expressions?

Yes, there are rules for using Matlab operators in expressions. These include the order of operations (PEMDAS), which dictates the order in which operators are evaluated, and the use of parentheses to control the order of evaluation. It is important to understand these rules in order to write accurate and efficient code in Matlab.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
823
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
Replies
3
Views
401
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
5K
Back
Top