% Modeling and Simulating Social Systems with MATLAB % http://www.soms.ethz.ch/matlab % Author: Stefano Balietti and Karsten Donnay, 2012 function [density, flow] = simulate_cars(moveProb, inFlow, withGraphics) % This function is simulating cars on a highway % INPUT: % moveProb: the probability for a car to move forwards, 0..1 % inFlowProb: The inflow volume to the road, 0..1 % withGraphics: Should the road be animated? true/false % OUTPUT: % density: the average vehicle density, 0..1 % flow: the average flow of cars, 0..1 % set parameter values N=40; % road length nIter=100; % number of iterations % define road (1=car, 0=no car) x = rand(1,N)