How can I predict the number of runs scored?

1 view (last 30 days)
David Reske
David Reske on 24 Apr 2019
Edited: James Tursa on 24 Apr 2019
I am trying to run a simulation to see how many runs would be scored in a 9 inning baseball game if every batter got a single half the time, and got out the other half of the time. Obviously, after three outs in an inning, the bases would be emptied
  2 Comments
James Tursa
James Tursa on 24 Apr 2019
Edited: James Tursa on 24 Apr 2019
What have you done so far? What specific problems are you having with your code? Do you know how to simulate an at-bat? Do you know how to simulate runners advancing? Do runners only move one base on a single? If the batter gets out, is it always a strikeout or do runners advance? Etc.
David Reske
David Reske on 24 Apr 2019
I'm mainly just wondering how i would start this.
I know that:
Each result is either a hit or an out.
It takes 4 hits (singles) before 3 outs are made to score a run
For every hit after 4 hits, but before 3 outs are made, run + 1
Every time the # of outs= 3, we reset the model, and keep track of the runs.
To simulate the game, I would have the program run 9 times for the 9 innings.
Since I am new to matlab and coding, I want to start simple, so I will say that it is either a single or strikeout, and runners do not advance on strikeouts.

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 24 Apr 2019
Edited: James Tursa on 24 Apr 2019
I will get you started. You need to write a code outline for how you would do it, e.g., with commenting, and then fill in the code. For example, a code outline could look something like this:
runners = zeros(1,3); % initialize runners on base for three bases, 0 = not on base, 1 = on base
outs = 0; % initialize number of outs
inning = 1; % initialize inning
phit = 0.5; % initialize probability of a hit
runs = 0; % initialize the number of runs
while( inning <= 9 )
% insert code here to see if you got a hit
% if you got a hit, then
% insert code here to advance all runners and possibly score a run
% else
% insert code here to increase the number of outs for this inning
% if the number of outs is 3, insert code here to reset the states and increment the inning
end
So, I wrote a bunch of comments to myself stating what the code would do. Once you get that to an algorithm you like that you think will work, you would need to replace the comments with actual code and then start testing it.

Categories

Find more on Strategy & Logic in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!