Question

3. Create vector V of integers randomly distributed on [-10 20] .display the vector. a) Use...

3. Create vector V of integers randomly distributed on [-10 20] .display the vector. a) Use for-end loop to examine each element of the vector. If element is positive double its value ; if element is negative triple its value. Display the result. b) without using for loop find number of elements in V that are greater than 1 c) without using for loop find all of elements in V that are greater or equal to -7 and are less or equal to 15

Homework Answers

Answer #1

MATLAB Code:

close all
clear
clc

V = -10 + (20 - (-10))*rand(1, 10)

W = V;
for i = 1:length(W)
if W(i) > 0
W(i) = 2*W(i);
else
W(i) = 3*W(i);
end
end
disp('Result of Part (a):'), disp(W)

l = length(find(V > 1));
disp('Result of Part (b):'), disp(l)

W = V((V >= -7) & (V <= 15));
disp('Result of Part (c):'), disp(W)

Output:

V =
-7.7180 -7.3168 7.5850 -5.2357 6.7987 3.0948 3.0226 -2.0542 13.7231 5.4227
Result of Part (a):
-23.1541 -21.9505 15.1700 -15.7070 13.5974 6.1896 6.0453 -6.1625 27.4462 10.8454
Result of Part (b):
6
Result of Part (c):
7.5850 -5.2357 6.7987 3.0948 3.0226 -2.0542 13.7231 5.4227

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please use this template. In this exercise you are to use a vector to store integers...
Please use this template. In this exercise you are to use a vector to store integers entered by the user. Once you have filled the vector, ask the user for a value to search for. If found, remove the value from the vector, keeping all other values in the same relative order, and then display the remaining values. #include <iostream> #include <vector> #include <climits> using namespace std; //Fills vector with user input until user enters 0 (does not include 0...
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
Question Recursive Maximum: In this question you must develop and use a recurive function to find...
Question Recursive Maximum: In this question you must develop and use a recurive function to find the maximum value in array of integers. Complete the C program, Maximum.c, by implementing the recursive function maximumValue, and the regular function max, and completing the main function using the comments provided. Open the file Maximum.c, complete, compile and run it. When you are sure it is correct, include the c file in your final submission. Note that the function max is not recursive....
For this assignment you need to write a parallel program in C++ using OpenMP for vector...
For this assignment you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is: #pragma...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
-Data Structure in C++ (Review for C++) -using vector and class In this assignment you’re going...
-Data Structure in C++ (Review for C++) -using vector and class In this assignment you’re going to build a simple “register machine”, a kind of minimal computer that only supports storing a fixed number of values (i.e., no randomly-accessible “main memory”). Your machine will consist of an input loop that reads lines of input from the user and then executes them, stopping when the user quits (by executing the stop command). Each line of input consists of a command followed...
Income Concepts 1.    When Contract rent is established as equal to the market level, this is...
Income Concepts 1.    When Contract rent is established as equal to the market level, this is no Economic rent Excess or deficit rent Market value Reversionary benefit 2. A Property is leasing for $900 per month and the appraiser concludes the market rent is $800 per month. The result is a(n)                A) deficit of $100 to the lessee’s advantage.                B) deficit of $100 to the lessor’s advantage.                C) excess of $100 to the lessee’s advantage.                D)...
MATH220 Lab04 Due Date: See ACE Excel File: Lab2204-182.xlsx 1 Question 1: (by hand) A retail...
MATH220 Lab04 Due Date: See ACE Excel File: Lab2204-182.xlsx 1 Question 1: (by hand) A retail establishment accepts either the American Express card or the VISA credit card. A total of 30% of its customers carry an American Express card, 70% carry a VISA card, and 20% carry both. a) Find the probability that a randomly selected customer carries at least one of the two credit cards. i) Draw a Venn diagram and shade the region corresponding to at least...
Part 1: Two Round Conductors Gather all items required for the exercise. Note: If using the...
Part 1: Two Round Conductors Gather all items required for the exercise. Note: If using the lab kit box, remove contents and place in a secure area. Put on your safety goggles. Center the black conductive paper on the top of the box, grid-side up. Place the two metal nuts (conductors) at the (5 cm, 10 cm) and (20 cm, 10 cm) positions on the paper. Secure using two dissection pins for each conductor. See Figure 13. Note: Place the...