I need help indexing into my container for the highest value (MATLAB). Attached is my code. I have tried to do this in many ways, but the val(i) values are incapsulated with parenthesis and this presumably keeps the max function from working.
%question 2 cme106 pset 4
profit = 0;
Optimal_Q = 0;
expected_profit_dict = containers.Map; %Dict
for Units_Q = (80:1:140)
sum = 0;
for Average_Demand = (80:1:140)
if Units_Q<= Average_Demand
profit = Units_Q*0.6;
disp('units_Q LESS THAN')
disp(profit)
sum = sum + profit;
else if Units_Q>Average_Demand
profit = (0.6*Units_Q) - (0.4*(Units_Q - Average_Demand));
disp('units_Q GREATER THAN')
disp(profit)
sum = sum + profit;
%find expected profit for each Q value
end
end
if Average_Demand == 140
n = 140;
expected_profit = sum/n;
disp('EXPECTED PROFIT')
disp(expected_profit)
Units_Q_title = string(Units_Q);
expected_profit_dict(Units_Q_title) = expected_profit;
end
end
end
disp(expected_profit_dict)
k = keys(expected_profit_dict);
val = values(expected_profit_dict);
%disp(val)
v_prev = 0;
v_new = 0;
for i = 1:length(val)
val(i) = v_new;
if v_new - v_prev <= 0
optimal_Q = expected_profit_dict(v_new);
disp('Optimal_Q:')
disp(Optimal_Q)
else
v_new = v_prev;
end
end