subject

In this problem you will perform various tasks on a 1-by-n array V, whose elements are either 1 or 0. For example, in Matlab: begin code 1 V = [1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1); end code For each of the following tasks test your code for many different values and lengths of V. (a) Write code using a for loop that will flip every third entry of Vie make the entry 0 if it is 1 or make it 1 if it is 0). This loop should modify V directly. For example V - ti, 1, 0, 1, 0, 1, 1, 0, 1) would become V = [1, 1, 1, 1, 0, 0, 1, 0, 0).
(b) Write code using a for loop that will flip every third instance of the number 1 in V. This loop should modify V directly. For example V - (1, 1, 0, 1, 0, 1, 1, 0, 1) would become V - 11, 1, 0, 0, 0, 1, 1, 0, 0).
(c) Write code using a for loop that will assign to the variable numChanges the number of times that successive elements of V change from 0 to 1 or from 1 to 0. For example if V - 10, 0, 1, 1] then numChanges would equal 1 and if V - (0, 1, 0, 1) then numChanges would equal 3
(d) Write code using a for loop that assigns to a variable nunOccurs the number of times a certain pattern, specified by the variable pattern occurs in V. For this problem, overlap is allowed, i. e. if pattern - [0, 1, 0) then the last 0 of an occurrence of [0, 1, o can be the first 0 of the next occurrence. For example, if V = [0, 1, 0, 1, 0) then two instances of [0, 1, 0 should be counted and numOccurs should equal 2.
(e) Write code using a while loop that will assign to the variable numDccuraSep the number of times a certain pattern of O's and 1's occurs separately in V. The variable pattern gives 3 of 4 the certain pattern to look for. For this problem overlap is not allowed, ie if pattern - [0, 1, 0] then the last 0 of an occurrence of 10, 1. O cannot be the first 0 of the next occurrence. For example, if V = [0, 1, 0, 1, 0) then only one instance of [0, 1, 0 should be counted and numOccursSep should equal 1.
(f) Write code using a while loop that will replace a sequence, specified by the variable seqremove, with a sequencespecified by the variable seqNew seqRemove and seqNew are the same size. For this problem once a sequence is replaced, only elements following the replaced sequence should be considered. For example if seqRemove - [0, 0], seqNew - [1, 0] and V - (1, 0, 0, 0, 1), then V should become [1, 1.0, 0, 1) and not [1, 1, 1,0, 11

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 16:30
Margins can be modified in the page layout tab or by using
Answers: 2
question
Computers and Technology, 23.06.2019 14:00
What is html ? give a small description about html
Answers: 2
question
Computers and Technology, 23.06.2019 15:00
1. which of the following statements are true about routers and routing on the internet. choose two answers. a. protocols ensure that a single path between two computers is established before sending packets over it. b. routers are hierarchical and the "root" router is responsible for communicating to sub-routers the best paths for them to route internet traffic. c. a packet traveling between two computers on the internet may be rerouted many times along the way or even lost or "dropped". d. routers act independently and route packets as they see fit.
Answers: 2
question
Computers and Technology, 23.06.2019 17:30
When making changes to optimize part of a processor, it is often the case that speeding up one type of instruction comes at the cost of slowing down something else. for example, if we put in a complicated fast floating-point unit, that takes space, and something might have to be moved farther away from the middle to accommodate it, adding an extra cycle in delay to reach that unit. the basic amdahl's law equation does not take into account this trade-off. a. if the new fast floating-point unit speeds up floating-point operations by, on average, 2ă—, and floating-point operations take 20% of the original program's execution time, what is the overall speedup (ignoring the penalty to any other instructions)? b. now assume that speeding up the floating-point unit slowed down data cache accesses, resulting in a 1.5ă— slowdown (or 2/3 speedup). data cache accesses consume 10% of the execution time. what is the overall speedup now? c. after implementing the new floating-point operations, what percentage of execution time is spent on floating-point operations? what percentage is spent on data cache accesses?
Answers: 2
You know the right answer?
In this problem you will perform various tasks on a 1-by-n array V, whose elements are either 1 or 0...
Questions
question
Social Studies, 26.03.2020 23:24
Questions on the website: 13722363