What Does the MATLAB Operator <~ Do?

  • Thread starter Thread starter Eastonc2
  • Start date Start date
  • Tags Tags
    Matlab Operator
AI Thread Summary
The MATLAB operator <~ is a combination of logical negation and comparison. The expression z = y < ~x compares each element of vector y with the logical negation of vector x, where ~x converts non-zero elements to 0 and zero elements to 1. This results in a vector z that contains 1s where elements of y are less than the corresponding elements of ~x, and 0s otherwise. However, there is confusion regarding whether the comparison should be < or <=, with some participants suggesting that the original problem intended to use the latter. Understanding the logical negation and its implications on comparisons is crucial for correctly interpreting the operation.
Eastonc2
Messages
19
Reaction score
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
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.
 
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.
 
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 <.
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...

Similar threads

Back
Top