Building a matrix model

Hi, I am trying to determine the corresponding Q value associated with the minimum value of each row of the matrix Wi. Below is the code.
%establishing order size%
Q = [0:0.1:2000]; %order size%
n = [1:1:3]; %number of products%
%matrix for each products demand and costs%
Pi = [200 100 10; 150 1500 5; 250 500 25;];
%matrix for total cost for each product%
Wi = (Pi(n,1).*Pi(n,2))./(Q)+(Pi(n,3).*(Q))/(2)
%determining minimum costs for each product%
minWn = min(Wi,[],2)
[Q Wi]=fminsearch(@(Q) fun,Wi)
%plotting function%
plot(Q, Wi)
How can I fix this?

回答(1 个)

You can use the second output from the min function to get the index where the minimum Wi occurs. Then use that index to get the corresponding Q value.
%establishing order size%
Q = [0:0.1:2000]; %order size%
n = [1:1:3]; %number of products%
%matrix for each products demand and costs%
Pi = [200 100 10; 150 1500 5; 250 500 25;];
%matrix for total cost for each product%
Wi = (Pi(n,1).*Pi(n,2))./(Q)+(Pi(n,3).*(Q))/(2)
Wi = 3×20001
1.0e+06 * Inf 0.2000 0.1000 0.0667 0.0500 0.0400 0.0333 0.0286 0.0250 0.0222 0.0200 0.0182 0.0167 0.0154 0.0143 0.0133 0.0125 0.0118 0.0111 0.0105 0.0100 0.0095 0.0091 0.0087 0.0083 0.0080 0.0077 0.0074 0.0072 0.0069 Inf 2.2500 1.1250 0.7500 0.5625 0.4500 0.3750 0.3214 0.2813 0.2500 0.2250 0.2045 0.1875 0.1731 0.1607 0.1500 0.1406 0.1324 0.1250 0.1184 0.1125 0.1071 0.1023 0.0978 0.0938 0.0900 0.0865 0.0833 0.0804 0.0776 Inf 1.2500 0.6250 0.4167 0.3125 0.2500 0.2083 0.1786 0.1563 0.1389 0.1250 0.1137 0.1042 0.0962 0.0893 0.0834 0.0781 0.0736 0.0695 0.0658 0.0625 0.0596 0.0568 0.0544 0.0521 0.0500 0.0481 0.0463 0.0447 0.0431
%determining minimum costs for each product%
[minWn,minWn_idx] = min(Wi,[],2)
minWn = 3×1
1.0e+03 * 0.6325 1.5000 2.5000
minWn_idx = 3×1
633 3001 1001
minQ = Q(minWn_idx)
minQ = 1×3
63.2000 300.0000 100.0000
% [Q Wi]=fminsearch(@(Q) fun,Wi)
%plotting function%
plot(Q, Wi)
hold on
for nn = n
plot(minQ(nn),Wi(nn,minWn_idx(nn)),'o')
end
set(gca(),'YScale','log')

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

版本

R2021a

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by