Building a matrix model
Mostra commenti meno recenti
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?
Risposte (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')
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
