Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python code for root finding problem. Do not use numpy or other python modules b

ID: 3748941 • Letter: P

Question

python code for root finding problem.

Do not use numpy or other python modules but math and copy. Give a well explained comments. The code should be as for python beginners, so be very didactical.

Please do no answer if it is 09.17.18 20:00 hrs GMT

Write a Python program that mcets the following requirements a) The program must have a function named Norm(x). This function has one argument named x, a b) The program has a function named CumNorn(xval). This function has one argument named xval, floating point number. This function must calculate and return the value of the Normal function as defined above, for the valuc of x passed in. (This should require 2 lines of code) a floating point number. This function must calculate and return the value of the Cumulative Normal function for the given xval. This function does NOT print anything. You must use numerical integration in this function Note that we cannot perform numerical integration with a lower limit of minus infinity. Instead, use a lower limit of (-5). That is surprisingly close enough. (This should require 2 or 3 lines of code c) The program has a function named InvCumNorm(given Value). This function has one argument named givenValue, a floating point number. This function must calculate and return the value of the Inverse Cumulative Normal for the given Value. This function does NOT print anything. You must use your Secant) fuction in this function. I suggest starting guesses in the near xval d) The main program: a. Calls Norm(1.5) and prints the answer, nicely formatted, with a label. Calls CumNorm(1.5) and prints the answer, nicely formatted, with a label. c. Calls InvCumNorm(0 90) and prints the answer, nicely formatted, with a label.

Explanation / Answer

import math # For basic math functions

from scipy.integrate import quad # for integration

x_norm = 0.0 #Globally declared to use anywhere in program

x_cumnorn = 0.0

def Norm(x):

pi = 3.1415926

denominator = (2*pi)**0.5

numerator = math.exp(-(float(x)**2)/(2))

ans = numerator*denominator

return ans

def xval_func(x):

x = x_norm

return x

def CumNorn(xval):

ans,err = quad(xval_func, 1.5, -5)

return ans

def InvCumNorn(givenValue):

ans = x_cumnorn - givenValue

return ans

if __name__ == '__main__':

x_norm = Norm(1.5)

print("Normal Value : ", x_norm)

x_cumnorn = CumNorn(1.5)

print("Cumalative Normal : ", x_cumnorn)

x_invcumnorn = InvCumNorn(0.90)

print("Inverse Cumalative Normal : ",x_invcumnorn)