% % Written by: % -- % John L. Weatherwax 2007-09-10 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- close all; drawnow; clc; clear; % sample_discrete.m addpath( '/home/wax/Programming/Matlab/Code/ExternalSources/Engineering/BayesianNetworks/FullBNT/KPMstats/' ); nDays = 5; if( 1 ) % could use these as the random numbers used in generating the demands: % us = [ 0.1048, 0.22368, 0.24130, 0.42167, 0.37570 ]; % % they map into the following demands: demands = [ 1, 1, 1, 2, 2 ]; else % instead generate some of our own: % demands = sample_discrete( [0.1, 0.2, 0.3, 0.25, 0.15], 1, nDays ); demands = demands - 1; % <- convert into physical demands (0 based) end S = 3; s = 0; xs = [ 3 ]; for di=1:nDays, d_np1 = demands(di); if( xs(end)>s ) xs(di+1) = xs(end)-d_np1; else xs(di+1) = S-d_np1; end end fprintf('the states we found are given by:\n'); fprintf('%5d',xs); fprintf('\n');