1 answer

Create a program named my_dotProduct which USING LOOPS calculates the dot product of two vectors

Question:

Problem 2: Matrix Vector Operations [5pt] a) Create a program named my_dot Product which USING LOOPS calculates the dot prod-

Problem 2: Matrix Vector Operations

a) Create a program named my_dotProduct which USING LOOPS calculates the dot product of two vectors (of dimensions \(1 \times n\) ) from the keyboard. The program should check the input from the user making sure that the vectors are the right dimensions. If the vectors are not then an error message should be outputted to the user. If the vectors are of the right dimensions then the answer should be outputted to the user. Using your code, complete the following table:

b) Create a program named my_arrayCount which inputs an \(n \times m\) array and determines (USING LOOPS) how many elements in the array are greater than zero and how many are less than zero. The program should then output the answers. Using your code, complete the following table:


Answers

Below are the code in MATLAB for the above questions:

(my_dotProduct.m)

clear,clc;
%taking input vector u,v from user.
u = input('Enter the elements of vector u: ');
v = input('Enter the elements of vector v: ');

%storing length of both vectors in n and m respectively.
n=length(u);
m=length(v);

%checking for dimension mismatch.
if(n==m)
%variable result that stores dot product of vector u and v.
result = 0;
%finding dot product.
for i = 1 : n
result = result + u(i)*v(i);
end
%displaying result.
fprintf('u.v = %d\n',result);
else
%displays error if vector mismatch.
disp('Error:vector dimension mismatch');
end

(my_arrayCount.m)

clear,clc;
%taking nxm array input from the user.
arr = input('enter the size of 2D array: ');
%storing dimension of array arr.
[n, m] = size(arr);
%variables which stores count of negative and
%positve numbers in an array arr.
neg = 0;
pos = 0;

%iterating in the array.
for i = 1:n
for j = 1:m
%array is less than zero then increment neg.
if(arr(i,j)<0)
neg = neg + 1;
else
%else we increment pos.
pos = pos + 1;
end
end
end
%displaying count of pos and neg in the array arr.
fprintf('n(>0): %d\nn(<0): %d\n',pos,neg);

Refer to the screenshot attached below to better understand the code and indentation:

(my_dotProduct.m)
1- my_dotProduct. m x my_arrayCount. m x + clear, clc; ftaking input vector u,v from user. u = input(Enter the elements of v
Output:
Enter the elements of vector u: (3 -24) Enter the elements of vector v: [2 2 -3] u.v = -10

Enter the elements of vector u: 0 0 -1] Enter the elements of vector v: [1 0 0] u.v = 0

Enter the elements of vector u: [2 1 2] Enter the elements of vector v: (-1 2 5] u.v = 10
a)
--- -------------------- IV ----- I u.V 31-2j+4k | 2i+2j-3k | -10 0i+0j-1k | 11-6j+ek o 2i+1j+2k -1i+2j+5k | 10


(my_arrayCount.m)
my_dotProduct.m x my_arrayCount. m x + clear, clc; Staking nxm array input from the user.</p><p>Arr = input(enter the size of 2D a
Output:
enter the size of 2D array: (3,2,-1,5,0,-2,-3] n>0: 4 n<0: 3

enter the size of 2D array: n>0: 2 n<0: 2

enter the size of 2D array: [1 -2 3; 2 10 -10; -pi 5 3; -5 17 20] n>0: 8 n<0: 4

b)
Array n(>0) n(<0) [3,2,-1,5,0-2-3] [H1 2 3 2 -10 -12 - 53 5 17 20]

If my answer helps you then please Upvote,
for further queries comment below.


Thank You.

.

Similar Solved Questions

1 answer
At May 31, 2017, the accounts of Lopez Company show the following. 1. May 1 inventories—finished...
At May 31, 2017, the accounts of Lopez Company show the following. 1. May 1 inventories—finished goods $14,300, work in process $17,400, and raw materials $8,800. 2. May 31 inventories—finished goods $9,900, work in process $16,000, and raw materials $7,500. 3. Debit postings t...
1 answer
Whats the effect of phosphorylation on the activity of the following enzymes? 1. glycogen phosphorylase 2....
whats the effect of phosphorylation on the activity of the following enzymes? 1. glycogen phosphorylase 2. glycogen synthase 3. acetyl CoA carboxylase...
1 answer
Suppose that there is incoming demand of 179 units of a certain product at the start...
Suppose that there is incoming demand of 179 units of a certain product at the start of 3, and 91 units of the same product at the start of week 6. Scheduled receipts of 120 are planned for week 2, and 90 for week 5. The product has a lead time of 1 week and must be ordered in batches of s. When, an...
1 answer
E10-33 (similar to) Racing Radars manufactures radar systems. It has just completed the manufacture of its...
E10-33 (similar to) Racing Radars manufactures radar systems. It has just completed the manufacture of its first newly designed system, RS-32. Manufacturing data for the RS-32 follow: E (Click icon to view data) Requirement Calculate the total variable costs of producing 2, 4, and 8 units A Data Tab...
1 answer
Problem 9-7 WACC Shi Import-Export's balance sheet shows $300 million in debt, $50 million in preferred stock, and...
Problem 9-7 WACC Shi Import-Export's balance sheet shows $300 million in debt, $50 million in preferred stock, and $250 million in total common equity. Shi's tax rate is 35%, -7%, -5.7%, and r, 10%. If Shi has a target capital structure of 30% debt, 5% preferred stock, and 65% common stock w...
1 answer
Vulcan Company’s contribution format income statement for June is as follows: Vulcan Company Income Statement For...
Vulcan Company’s contribution format income statement for June is as follows: Vulcan Company Income Statement For the Month Ended June 30 Sales $ 900,000 Variable expenses 400,000 Contribution margin 500,000 Fixed expenses 470,000 Net operating income $ 30,000 Management ...
1 answer
Of the following five prime numbers which ones could be used to create the Rabin Cryptosystem?...
Of the following five prime numbers which ones could be used to create the Rabin Cryptosystem? And why (or why not? 1. 951781 2. 852391 3. 2027 4. 555557 5. 100003 ....
1 answer
X Incorrect. Predict the major product(s) for the following reaction: Br 827 H20 Heat 111110H Edit
X Incorrect. Predict the major product(s) for the following reaction: Br 827 H20 Heat 111110H Edit...
2 answers
(Bond valuation) You own a 10-year, $1,000 par value bond paying 8 percent interest annually. The...
(Bond valuation) You own a 10-year, $1,000 par value bond paying 8 percent interest annually. The market price of the bond is $900, and your required rate of return is 11 percent. a. Compute the bond's expected rate of return. b. Determine the value of the bond to you, given your required rate o...
1 answer
2018 2019 Assets Current assets Cash $ 5,298 $ 5,827 Accounts receivable 7,707 9,477 Inventory 12,150...
2018 2019 Assets Current assets Cash $ 5,298 $ 5,827 Accounts receivable 7,707 9,477 Inventory 12,150 22.956 2018 2019 Liabilities and Owners' Equity Current liabilities Accounts payable $ 3,754 $ 5,986 Notes payable 2,045 3,055 Other 152 179 Total $ 25,155 $38,260 Total $ 5,951 $ 9,220 $.22,700...
1 answer
Apter 4 ems Help Save &Exit Submit Lubricants, Inc., produces a special kind of grease that...
apter 4 ems Help Save &Exit Submit Lubricants, Inc., produces a special kind of grease that is widely used by race car dinvers The grease is produced in two departments Refining and Blending. Raw materials are introduced at various points in the Refining Department 34,50 Completed and transferre...
1 answer
Extra Credit An unknown compound A of molecular formula of C10H180 reacts with H2SO4 and heat...
Extra Credit An unknown compound A of molecular formula of C10H180 reacts with H2SO4 and heat to form two compounds (B and C) of molecular formula C10H16. B and C both react with H2 over Pd/C to form decalin. Ozonolysis of B forms D, and ozonolysis of C forms a diketone E of molecular formula C10H16...
1 answer
An example of a common microeconomic model would be that blank? generally demands (or purchases) more...
An example of a common microeconomic model would be that blank? generally demands (or purchases) more goods or services at lower prices where blank?   would prefer to sell more goods at higher prices. Blank? (i think normative) economics is a term used to describe the economic outcomes tha...
1 answer
The following accounts are from last year's books at Sharp Manufacturing: Bal (a) Raw Materials 0...
The following accounts are from last year's books at Sharp Manufacturing: Bal (a) Raw Materials 0 (b) 168,500 12,700 155,800 517,200 Bal (b) (c) (e) Work In Process 0 (f) 132,900 169,800 214,500 0 Manufacturing Overhead 22,900(e) 26,900 157,800 Bal (f) Finished Goods 0(g) 517,200 48,200 469,000 ...
1 answer
The Bigbee Bottling Company is contemplating the replacement of one of its bottling machines with a...
The Bigbee Bottling Company is contemplating the replacement of one of its bottling machines with a newer and more efficient one. The old machine has a book value of $650,000 and a remaining useful life of 5 years. The firm does not expect to realize any return from scrapping the old machine in 5 ye...
1 answer
In General Chemistry we learned that the equilibrium constant for a reaction is related to AG,...
In General Chemistry we learned that the equilibrium constant for a reaction is related to AG, for 8. the reaction via AGo RTlnKeq- Given [0(AG/T)/aT]p = -AH/T2 Show that: [ (In Keg Tp-AH (RT)...
1 answer
A 2,500 square foot house in New Jersey costs $2,000 each winter to heat with its...
A 2,500 square foot house in New Jersey costs $2,000 each winter to heat with its existing oil-burning furnace. For an investment of $6,000, a natural gas furnace can be installed, and the winter heating bill is estimated to be $1,200. If the homeowner's MARR is 8% per year, what is the discount...
1 answer
12. Mortgage payments Mortgages, loans taken to purchase a property, involve regular payments at fixed intervals...
12. Mortgage payments Mortgages, loans taken to purchase a property, involve regular payments at fixed intervals and are treated as reverse annuities. Mortgages are the reverse of annuities, because you get a lump-sum amount as a loan in the beginning and then you make monthly payments to the lender...