Question

In: Computer Science

Directly using mathematical expression, DO NOT USE the built-in Python functions, evaluate the binomial function for...

Directly using mathematical expression, DO NOT USE the built-in Python functions, evaluate the binomial function for n = 20, p = 3/8. Make sure you plot your results (Remember the the binomial distribution is discrete)

Solutions

Expert Solution

import math

import numpy as np

import matplotlib.pyplot as plt

# function to calculate binomial co-efficient

def NchooseK(n, k):

    a = math.factorial(n)

    b = math.factorial(k)

    c = math.factorial(n - k)

    ret = a/(b * c)

    return ret


def PB(x, n, p):

    ans = (NchooseK(n, x))*(p**x)*((1-p)**(n-x))

    return ans


n = 20

xx = []  # initialise array to save x values from 0 to 8

yy = []  # initialise array to save PB(x,n,p) values for p = 0.5

p = 0.375

# save PB(x,n,p) values for p = 0.375

for x in range(0, 21):

    tmp = PB(x, n, p)

    xx.append(x)

    yy.append(tmp)

    print("n = ", n, " p = ", p, " x = ", x, " PB(x, n, p) = ", tmp)


# plot the data

plt.plot(xx, yy, color="red", label='PB(x,n,p) for p = 0.375')

plt.xlabel('x')

plt.legend(loc='upper right')

plt.show()

PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT SECTION


Related Solutions

PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS....
PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS.                          3)Use of string and char is not allowed.             Write a program in c laungage that prints a table of the binary, octal and hexadecimal equivalents of the decimal numbers in the range1 through 256.
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
You can only use built in Lisp functions and you cannot use setq function. Write a...
You can only use built in Lisp functions and you cannot use setq function. Write a function in Lisp called f1 that counts the number of lists in a list. Example: (f1 ‘(a (a b (b c)) c d (e))) returns 2
which statements are true about Python functions? a)Different functions cannot use same function name b)a function...
which statements are true about Python functions? a)Different functions cannot use same function name b)a function always returns some value c)different function cannot use the same variable names d) function must use the same parameter names as the corresponding variables in the caller what benefits does structuring a program through defining functions bring? a) there is a possibility of reducing the number of variables and/or objects that must be managed at any cost at any one point b)the program is...
C++ PROGRAMING Implement a program to evaluate simple mathematical expressions. Assume that the original expression is...
C++ PROGRAMING Implement a program to evaluate simple mathematical expressions. Assume that the original expression is provided to the program as a text string. Allowed expression tokens: brackets “(” and “)”, integers like “4”, “15”, addition “+”, subtraction “-”, multiplication “*”, division “/”. Output can be float. Trim spaces from an expression. Brackets should contain at least one operation. Make sure that an expression is validated before it is calculated; reject the invalid expressions with appropriate message. The program must...
Write functions that do the following in Python: i) A function that takes 2 arguments and...
Write functions that do the following in Python: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both.
Problem 3. Plot the following binomial probability functions as a function of outcome (x) using EXCEL...
Problem 3. Plot the following binomial probability functions as a function of outcome (x) using EXCEL on the same graph, and then comment on the effect of the value of p. a. b(x;10,0.1) b. b(x;10,0.5) c. b(x;10,0.9)
USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade...
USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade point average (GPA) on a scale of 0 to 4 where A = 4, B = 3, C = 2, D = 1, and F = 0. Your function should take as input two lists. One list contains the grades received in each course, and the second list contains the corresponding credit hours for each course. The output should be the calculated GPA. To...
Using Python math functions that produce x,y values. The results of these function calls will be...
Using Python math functions that produce x,y values. The results of these function calls will be used as input to another program of your choice for plotting the results. Plots can be completed using Excel any other online or other graphing tool you have available. Use standard I/O The Math functions and values range of x-values are described below: a. Generate x, sin(x) for x values ranging from -2PI -> 2PI with an increment of PI/64 b. Generate x, cos(x)...
Write functions in Python IDLE that do the following: i) A function that takes 2 arguments...
Write functions in Python IDLE that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT