numeric-methods-programming-python-d-68256
numeric-methods-programming-python-d-68256
Problem 1
def printMatrix(A):
"""
Printing the Matrix
"""
print 'MATRIX'
for i in A:
row='|'
for j in i:
row += str(j).rjust(3)
print row+'|'
print
# Original Matrix
A=[[11,0,0,0,0,0,14], [0,0,0,0,23,0,0], [0,0,0,0,33,34,0], [0,15,0,0,43,44,0], [0,0,0,0,0,54,0],
[0,0,62,0,0,0,0], [0,0,72,0,0,0,0]]
W W W . A S S I G N M E N T E X P E R T. C O M
DO MY ASSIGNMENT SUBMIT
OUTPUT
MATRIX
| 11 0 0 0 0 0 14|
| 0 0 0 0 23 0 0|
| 0 0 0 0 33 34 0|
| 0 15 0 0 43 44 0|
| 0 0 0 0 0 54 0|
| 0 0 62 0 0 0 0|
| 0 0 72 0 0 0 0|
Problem 2
a) Y=(5-x)*exp(x)-5
Code in function.py
W W W . A S S I G N M E N T E X P E R T. C O M
DO MY ASSIGNMENT SUBMIT
b) 4.96511423174
Code in secant.py
c) 4.96511423176
Code in newton.py
d)
Code in secant.py
Code in newton.py
W W W . A S S I G N M E N T E X P E R T. C O M
DO MY ASSIGNMENT SUBMIT
Problem 3
Here is the code
def f(x):
return log((1+x)*1.0/(1-x*x))
def bisection(f,a,b):
eps = 10**(-8) # accuracy
max_steps = 100000
k=0
while abs(b-a)>eps:
x = (a+b)/2 #next guess
if( f(a)*f(x)>0 ):
a=x
else:
b=x
#k += 1 #if needed to restrict the number of iterations uncomment this line
if(k>max_steps):
break
return x
print bisection(f,-3.0/4,1.0/4)
W W W . A S S I G N M E N T E X P E R T. C O M