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)
%determining minimum costs for each product%
[minWn,minWn_idx] = min(Wi,[],2)
minQ = Q(minWn_idx)
% [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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
