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 Secant(fcn, x0, x1, xtol=1e-5, maxiter=10): Purpose: use the Secant Method to find

we are using pycharm to write programs

Write a function defined as: def Secant(fcn, x0, x1, xtol=1e-5, maxiter=10): Purpose: use the Secant Method to find the root of fcn(x), in the neighborhood of x0 and x1. fcn: the function for which we want to find the root x0 and x1: two x values in the neighborhood of the root xtol: exit if the |xnewest - xprevious| < xtol maxiter: exit if the number of iterations (new x values) equals this number return value: the final estimate of the root (most recent new x value) and the number of actual iterations.

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions