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 GaussSeidel(Aaug, x, xtol = 1e-6, maxiter = 50): Purpose: use the Gauss-Seidel

we are using pycharm to write programs

Write a function defined as: def GaussSeidel(Aaug, x, xtol = 1e-6, maxiter = 50): Purpose: use the Gauss-Seidel method to estimate the solution to a set of N linear equations expressed in matrix form as A x = b. Aaug: an augmented matrix contining [A | b ] having N rows and N+1 columns x: a vector (array) contain the values of the initial guess xtol: exit if the magnitude of (xnew xold ) < xtol maxiter: exit if the number of iterations (new x vectors) equals this number return value: the most recent new x vector.

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions