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!
