Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

we are using pycharm to write programs Write a function defined as: def Simpson(fcn, a, b, npoints): Purpose: use Simpsons 1/3 rule to estimate the

we are using pycharm to write programs

Write a function defined as: def Simpson(fcn, a, b, npoints): Purpose: use Simpsons 1/3 rule to estimate the integral of fcn(x), between the limits of a and b. fcn: the function we want to integrate a and b: the lower and upper limits of integration npoints: The number of integration points used in the range a to b (inclusive). Npoints must be an ODD number. If npoints is not ODD, then add 1 to make it odd! return value: the estimate of the integral.

here is the main function if needed to run program:

from math import * def main(): def f1(x): return x - 2 * sin(x) def f2(x): return (x - a) * (x - b) * (x - c) * (x + c) #for part a) x0 = 1 x1 = 2 a,b,c,d = 2.5,7,4,2 root, niter = Secant(f1, x0, x1) print('the root is: {:.6f} after {:d} iterations'.format(root, niter)) root, niter = Secant(f2, x0, x1, xtol=0.001, maxiter=8) print('the root is: {:.6f} after {:d} iterations'.format(root, niter)) root, niter = Secant(lambda x: (x - 1.523) * (x - 5), x0, x1, xtol=1e-4, maxiter=6) print('the root is: {:.6f} after {:d} iterations'.format(root, niter)) root, niter = Secant(lambda x: x - 2 * sin(x), x0, x1, maxiter=2) print('the root is: {:.6f} after {:d} iterations'.format(root, niter)) # for part b) a = 1 b = 3 nsteps = 9 integral = Simpson(f1, a, b, nsteps) print('the integral of function 1 is: {:.7f} '.format(integral)) nsteps = 10 integral = Simpson(f1, a, b, nsteps) print('the integral of function 1 is: {:.7f} '.format(integral)) a = 0 b = 4 nsteps = 11 integral = Simpson(f2, a, b, nsteps) print('the integral of function 2 is: {:.2f} '.format(integral)) # for part c) MyA = [[4, -1, -1, 3], [-2, -3, 1, 9], [-1, 1, 7, -6]] MyX = [0, 0, 0] answer = GaussSeidel(MyA, MyX, maxiter=6) print(" ", answer) answer = GaussSeidel(MyA, MyX, maxiter=15, xtol = 1e-15) print(answer) #for part d) #From MAE 3013 ... the 3 male mice problem x = 2; n = 10; N = 100; M = 3 p = HyperGeometric(x,n,N,M) print(" the HyperGeometric probablilty is {:.5f}".format(p)) p = Binomial(x,n,M/N) print("the Binomial probablilty is {:.5f}".format(p)) main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Describe a limited liability company (LLC).

Answered: 1 week ago

Question

Draw a picture consisting parts of monocot leaf

Answered: 1 week ago