![Problem 2: Matrix Vector Operations [5pt] a) Create a program named my_dot Product which USING LOOPS calculates the dot prod-](http://img.homeworklib.com/questions/5542f2f0-a700-11eb-97e3-89ece276f438.png?x-oss-process=image/resize,w_560)
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:
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)
Output:
a)
(my_arrayCount.m)
Output:

b)
If my answer helps
you then please Upvote,
for further queries comment below.
Thank You.
Create a program named my_dotProduct which USING LOOPS calculates the dot product of two vectors
in c++ Write a program which can find the dot product of two vectors of the same length ?. The user will enter the length ?. Use the length to control how many times you loop. The result is a scalar value and not a vector. If the dot product is zero, then the two vectors are perpendicular.
using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...
Please write the code using matlab
1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...
C++ Create a program that finds the dot product of two vectors. I'm currently trying to display the dot product by calling the dotProduct member function however I am confused as to how to do this. What would be the proper way to display the dot product? I don't believe my dotProduct member function is set up correctly to access the proper data. Feel free to modify the dotProduct member function to allow for it to work with the other...
Create a function named determineList which inputs two characters of dimensions 1×1 which represent the start and end of the range. These two character datatype inputs can be of either alphabetic (A-Z,a-z) or digits (0-9) type. The function should then output a list (character array of dimension N × 1). (in matlab)
(CO 4 and 6) Create a program with a function named rollDice that will roll a dice as many times as the user asks and with a user specified number of sides. The function should return the roll of the die. The program should continue while the user presses Y. Sample output: How many times do you want to roll the die? 5 How many sides does the die have: 6 You rolled 1 You rolled 2 You rolled...
(COs 1 and 8) Create a Python program that calculates the tip and total for a meal at a restaurant. Paste Python code here; output not required. Sample output: Tip Calculator Enter cost of meal: 52.31 Enter tip percent: 20 Tip amount: 10.46 Total amount: 62.77 Specifications: •Input: costOfMeal, tipPercent The formula for calculating the tip amount is: tip = costOfMeal * (tipPercent / 100) • The program should accept decimal entries like 52.31 and 15.5. • Assume the user...
In Python Exercise – For & While Loops Create a new file called loops.py and use it for all parts of this exercise. Remember the difference between input and raw input? Be sure to test your code for each part before moving on to the next part. Write a program using a for loop that calculates exponentials. Your program should ask the user for a base base and an exponent exp, and calculate baseexp. Write a program using a while...
Write a Java program that calculates the sum of a variable sized matrix using a two dimensional array. (ArraySum.java) The user should provide the number of rows and columns Test multiple user inputs (3 times 2, 4 times 4, 6 times 2, etc) A sum should be created for each row, each column, and the total for the matrix Ex.: How big would you like your matrix? Rows - ? 3 Columns -? 2 Please enter your row 1? Column...
1) Create a matlab function that calculates:
for
Name your function TwoVarFunc :
The inputs should be in the same order:
xmin
xmax
ymin
ymax
N: n is the number of elements in the vector x and y
The ouputs should be in the same order:
f_xy: is the calculated array f(x,y)
f_xyMAX: should be the the maximum value of the function
f(x,y).
Hint: to create vectors x and y look up the matlab built-in
function linspace()
Hint 2: To...