Starting from:

$30

Computer Assignment 2

Computer Assignment 2
Deliverable: The solutions for the two exercises and a Python computer program that uses the
simulation approach outlined below (and in computer assignment 1) as the solution to the given
problem. To earn credit for the assignment the program must satisfy the rubric below.
Title: Three Solutions, Repeated Independent Trial Problem
Textbooks often have the answers to the problems in it in the back of the text. The student uses the
answers provided in the text to verify the correctness of their answers to problems. If you attempt to
solve a problem and the answer is not provided, you may not be able to verify whether you got the correct
answer. Assuming there does not exist an answer for the problem you have solved, how do you know
your answer is correct? To know that you have solved a problem correctly (or at least have confidence in
your answer) you need to solve it several different ways and then see if the answers are consonant. Each
approach to solving the problem must have a fundamentally different paradigm to support the argument
that the answer is valid.
-------------------------------------------------------------------------------------------------------------------------------
You will both from the standpoint of theory and from the standpoint of simulation using a Python
program address the following probability problem.
Problem: You have a coin with the probability of heads being 𝑝. Toss the coin until a head comes up for
the first time. What are the chances of that happening on an odd-numbered toss?
Exercise 1: Solve the problem by the direct approach of repeated independent trials. To do this it is
expected that you will make use of an infinite geometric series.
Hints:
With 𝑃({𝐻}) = 𝑝 we can look at the possible favorable outcomes and the associated probabilities. The
subscript indicates the number of the toss. (Refer to the note on geometric series.)
Outcome Probability
𝐻1 𝑝
𝑇𝑇𝐻3 (1 − 𝑝)
2𝑝
𝑇𝑇𝑇𝑇𝐻5 (1 − 𝑝)
4𝑝
and so forth indefinitely. Each trial is composed of independent events but all of the trials are mutually
exclusive. Write your solution with the relevant steps.
Exercise 2: Solve the problem using total probability. The event 𝐸 is ‘first head on an odd toss’. Cut the
sample space into two cases: first toss is heads 𝐻1or first toss is tails 𝑇1. N.B.: The subscript indicates
first toss.
{𝐸} = {𝐻1
} ∪ {𝐸 ∩ 𝑇1}
Hints: Apply conditional probability 𝑃(𝐴 ∩ 𝐵) = 𝑃(𝐴)𝑃(𝐵|𝐴) and model the sample space.
𝐻 Cut the sample space into two mutually exclusive events.
𝑇𝐻
𝑇𝑇𝐻
𝑇𝑇𝑇𝐻
𝑇𝑇𝑇𝑇𝐻
𝑇𝑇𝑇𝑇𝑇𝐻
𝑇𝑇𝑇𝑇𝑇𝑇𝐻
and so forth ad infinitum.
The first outcome in the sample space, 𝐻, is one of the desired outcomes. All the rest of the outcomes
share the same feature of tails on the first toss. Notice in this subset that the desired outcomes are
alternate outcomes. When you condition the event 𝐸 on tails on the first flip 𝑇1what is the new sample
space? What is the complement of the event 𝐸? Finally, how are 𝑃(𝐸|𝑇1) and 1 − 𝑃(𝐸) related?
Write your solution with the relevant steps.
Exercise 3: Frequency Simulation
Write a Python program that solves the problem using simulation. (Similar as to what was done in
computer assignment 1.) Simulation in this context means a computer program that models the
probability experiment and then repeat this experiment a large number of times. Correctly evaluating the
results of the simulation will make it possible to determine an approximate answer to the probability
problem. Some suggestions and comments are the following:
1.) The Python program simulating a Bernoulli random variable found in the note ‘Markov,
Introduction’ can be used to model the coin flip.
2.) Consider the Bernoulli trials repeating until the first ‘head’.
3.) In the Python language the code for the modulus or congruence operation is ‘%’. This can be
used to determine if the ‘head’ was on an odd flip.
4.) Keep a record of the length of each run.
5.) Use an accumulator to calculate the total number of wins.
6.) Possibly there will be a need to reset (assign initial value) variables.
7.) The number of iterations of the outer loop is significant.
-------------------------------------------------------------------------------------------------------------------------------
Additional Instructions: Use the solution from the exercises to obtain the exact (theoretical) results and
use the simulation to obtain the approximate results for the probability of heads: 𝑝 =
1
5
,
1
2
, and 2
3
.
Rubric
Name and I.D. #
Name of Assignment
Submission Date
Not Satisfactory:
Data requested absent.
Satisfactory:
Has all data requested.
Exercise 1. Solves problem
using geometric series
approach.
Not Satisfactory:
Missing steps.
No general solution.
Satisfactory:
Shows steps using geometric
series to obtain general
solution.
Exercise 2. Solves problem
using total probability
approach.
Not Satisfactory:
Missing steps.
No general solution.
Satisfactory:
Shows steps using total
probability to obtain general
solution.
A block comment at beginning
of program summarizing it. Line
comments throughout the
program explaining its
operation.
Not Satisfactory:
Conveying incomplete thoughts.
Satisfactory:
A brief two or three sentence
explanation at the beginning.
Sufficient line comments
explaining the code.
Identify lines in program that
model the experiment intrinsic
to the probability problem.
Not Satisfactory:
Experiment not identified or
blocked off.
Satisfactory:
Experiment clearly identified.
List references. Not Satisfactory:
No references listed.
Satisfactory:
References – assignment
handout, internet, students,
and etc. listed
Run the program with the three
values of 𝑝 listed and show the
corresponding output.
Not Satisfactory:
Not run for the values listed or
no output.
Satisfactory:
Run for three values of 𝑝 listed
with three output.
Submit solutions to exercises 1
& 2, the .py file of the program
to dropbox and a PDF of the
program with the output to
dropbox.
Not Satisfactory:
Absent solutions to exercises 1
& 2.
Absent files.
Absent output.
Satisfactory:
Solutions to exercises 1 & 2, a
copy of the Python file, the
output all in the PDF and the .py
file These two complete files
are submitted to dropbox.

More products