Question: 1. In MATLAB, there is a data type called logical of which variable instances of that type can take on the value of 0 or

1. In MATLAB, there is a data type called logical of which variable instances of that type can take on the value of 0 or 1 depending on whether or not the input value is true or false, respectively. This is closely related to the binary nature of computers, the existence of which is based on the on/off nature of computers. You can think of this on/off nature in the same way you might a traditional light bulb, i.e., the light bulb is either on or off. You can try a few examples in MATLAB. For example, if you type in x = 1.2, then typing in logical(x) will produce 1 as an answer, where 1 is of type logical that is equivalent to the MATLAB variable true. You can type true or x = true into a MATLAB command window to see what appears (x will be 1). Use class(ans) or class(x) immediately after to see the class of true or x, respectively. On the other hand, logical(0) will produce 0 as an answer, where 0 is of type logical that is equivalent to the MATLAB variable false. In general, any true statement of any kind or nonzero number a has logical value of 1, or true, and any false or (numerically) 0 number b has logical value 0, or false. In the MATLAB command window, type in doc, hit enter, and then type in the word logical into the search bar to get a list of relevant logical operators and commands. Pay attention, in particular, to the following results that you will potentially use in this problem: logical logical operators: short-circuit && ||. Explore &, | if you see that tab somewhere in your version of MATLAB. Otherwise, you can experiment with them in MATLAB. Note the difference between these two and the previous two binary operators. logical operations truth table for logical operators. Some other relational (unary, binary) operators that you should look up are ?, ==, ?= , >=, <=, <, >. These are, in order, negation, test for equality, test for inequality, test for equality or greater than, test for equality or less than, test for less than, test for greater than. Note that with the exception of the first one, these relational operators work on two variables a,b, i.e., as an example, we can test (0<1) in MATLAB and we observe a result of 1 or logical true. Feel free to play around with these (try using ? on 1). This exercise involves three variables and algebra on logical/boolean variables (boolean variable are 0/1 ?? true/false values that we have seen). Define the following variables: one = 1 zero = 0 s = RandStream.create(mt19937ar,seed,mmddyyyy); RandStream.setGlobalStream(s); x = -1 + (1-(-1))*rand(1) y= -1 + (1-(-1))*rand(1) Here, mmddyyyy is your birthdate. If you were born in a month before October, use mddyyyy. Note that the rand function gives a uniformly distributed number in [0, 1] (which is jargon for a real number between 0 and 1 is chosen at random). The algebra that was performed changes the interval to [?1, 1]. The code between the declaration of zero and x ensures that the random numbers x and y dont change everytime you run your code! Use the above to evaluate the following calculations. Note that you should use the fprintf or disp command to display each command before actually outputting it. For example, to carry out the sixth bullet for presentation purposes, you should write in your MATLAB file the following: fprintf( 10*one)>=10 ) disp((10*one)>=10)) Here, the is MATLAB for return or next line for display purposes. 1. one 2. zero 3. ? one 4. ? zero 5. one>0 6. (10*one)>=10 7. (10*one)>10 8. x>zero 9. x<=0 10. (x>zero + x<=zero) 11. 10*(x>zero + x<=zero) 12. zero==0 13. one?=1 14. true 15. false 16. logical(true) 17. logical(false) 18. logical(10*(x>zero + x<=zero)) 19. (x>zero)*(x<=zero) 20. (x>zero||x<=zero) 21. (x>zero&&x<=zero) 22. (zero<=x&&x<=one) 23. one||zero 24. ([one zero x]>=x).*[1 2 3] 25. ([one zero x])==true(1,3) 26. ([one zero x>0])==true(1,3) 27. ([one zero x]) < 3 28. ([one zero x])>=0 29. ([one zero x]).*?logical([one zero x]) 30. ([one zero x>0])==false(1,3) 31. ([one zero x]) ==1 32. ([one zero x]) =false In the last nine examples were did logical comparisons between vectors of the same size and vectors and constants. Similarly can be done between matrices of the same size and matrices and constantsAlso, for each of the relational operators &&, ||, %, |, perform the comparisons one**one, one**zero, zero**one, zero**zero, where ** is one of the four mentioned relational operators (sixteen comparisons total). Look up each of those relational operators and explain either by comment or using fprintf the difference between % and %% and | and ||. It might help if you write some comments as to what is going on with each command if you need to keep track, but this is not required.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!