The following is a problem that is to be solved via MATLAB programming. Note tha
ID: 672831 • Letter: T
Question
The following is a problem that is to be solved via MATLAB programming.
Note that built-in "min" functions ARE NOT ALLOWED to complete the assignment.
2. Problem ICA 20-10, page 739 You are assessing the price of various components from different vendors and wish to find the least expensive vendor for each component. The prices of the parts from each vendor are stored in a matrix, vendcost. Each row corresponds to a specific vendor and each column corresponds to a specific component. If a specific part is not offered by a vendor, the corresponding entry will be -1 Write a program that will determine which vendor offers the cheapest price for each component, and place the results in a two-row matrix cheapest with the same number of columns as there are columns in Vendcost. Each entry in the first row of cheapest should be an integer corresponding to the row number of the vendor with the cheapest price for the corresponding component, and the entries in row #2 should contain the lowest price for that component. You may assume that each part is available from at least one of the listed vendors. Iftwo or more vendors offer a component at the same lowest price, you may choose either one You may not use the built-in min function or other similar functions to solve this problem You may not use direct matrix operations to solve this problem; you must do it using for loops (in a meaningful way). Your solution must work for any number of vendors and any number of components Example vendCost- 4.97 8.54 2.04 0.44 13.55-1.00 5.23 8.23 2.12 0.39 15.98 2.67 5.24 8.22 2.09 0.51 -1.00 2.76 Cheapest 4.97 8.22 2.04 0.39 13.55 2.67Explanation / Answer
VendCost = [[1,2,3,4,5];[0.3,9.4,2,5,2];[.4,.4,.2,9,.4]];
[r,c] = size(VendCost);
Cheapest = zeros(2,c)
for i = 1:c
Cheapest(1,i) = i;
end
for i = 1:c
min = VendCost(1,i);
for j = 2:r
if VendCost(j,i) < min
min = VendCost(j,i);
end
end
Cheapest(2,i)=min;
end
Cheapest
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.