1 Advanced Plotting 2 (Example from Aj.Jim) ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
2 Inventory Problem Here are projected sales for 10 weeks: Week: Sales: Each week the company can manufacture 1,000 units, and only sells units that are finished and "in stock". So the sales & inventory balance for week k is: Production = 1000 Sales(k) = minimum( ProjectedSales(k), Inventory(k) ) Inventory(k+1) = Inventory(k) + Production - Sales(k) Starting inventory at week 1 is 200. Compute the actual sales.
3 Inventory Problem Formulation 1.Formulate your solution method on paper. 2.Write a flow chart for your solution on paper. 3.Create an m-File to implement the flow chart.
4 Inventory Problem Solution (1) 3. Create an m-File to implement the flow chart. % Projected sales for each week psales = [ ]; % Production each week production = 1000; % Initial inventory: inventory(1) = 200; % Inventory - sales - production balance for week k sales(k) = min( psales(k), inventory(k) ); inventory(k + 1) = inventory(k) + production - sales(k);
5 Inventory Problem Solution (2) 3b. Add a "for" loop for each week... % SalesForecast.m % Projected sales for each week psales = [ ]; % Production each week production = 1000; % Initial inventory: inventory(1) = 200; % Inventory - sales balance for week k for k=1:10 sales(k) = min( psales(k), inventory(k) ); inventory(k + 1) = inventory(k) + production - sales(k); end
6 Inventory Problem Solution (3) Run the m-file and view the actual sales: >> SalesForecast >> sales sales = >> sum( sales ) ans = 9200 Too many numbers to interpret. What were the total sales?
7 Inventory Problem Solution (4) >> psales - sales ans = How many sales were "lost" due to insufficient "stock"? Maybe we should hire some O.T. during week 1, 5, and 6 to increase production during those weeks?
8 Inventory Problem Solution (5) Plot proj. sales, actual sales, and inventory on one plot: >> week = 1:10 >> plot( week, psales, 'bo:', week, sales, 'gp--', week, inventory(1:10), 'rx' ) >> legend( 'projected sales', 'sales', 'inventory' )
9 Inventory Problem Solution (6) Plot projected sales, sales, and excess inventory. >> week = 1:10 >> plot( week, psales, 'bo:', week, sales, 'gp--', week, inventory(1:10)-sales, 'r^' ) >> legend( 'projected sales', 'sales', 'excess inventory' ) Hmmm... not much surplus inventory in weeks If sales are high, we're in bad shape.