Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python v3.9 please! I need help with this question.. i have the answer but not sure how to include the pivoting to get the right
Python v3.9 please! I need help with this question.. i have the answer but not sure how to include the pivoting to get the right answer. gausselim.py example: eq. (6.17): Exercise 6.2: a) Modify the program gausselim.py in Example 6.1 to incorporate partial pivot- ing (or you can write your own program from scratch if you prefer). Run your program and demonstrate that it gives the same answers as the original program when applied to Eq. (6.1). b) Modify the program to solve the equations in (6.17) and show that it can find the solution to these as well, even though Gaussian elimination without pivoting Answer: 61.619,-0.424, -1.238 1.3317 fails. don't do it wlo pivoting from numpy import array, empty A = array([[ 2, 1, 4, 1], [ 3, 4, -1, -1], [1, -4, 1, 5], [2, -2, 1, 3 ]], float) array([ -4, 3, 9, 7 ],float) N = len(v) V = # Gaussian elimination for m in range(N): # Divide by the diagonal element div = A[m,m] A[m, :] /= div v[m] /= div # Now subtract from the lower rows for i in range (m+1,N): mult = A[i,m] A[i, :] -= mult*A [m, :] v[i] -= mult*v [m] # Backsubstitution x = empty(N,float) for m in range (N-1,-1,-1): = for i in range (m+1,N): A[m,i] *x[i] print(x) 0 1 4 1 3 4 -1 -1 1 -4 1 5 2 -2 1 3 -4 3 9 7 (6.17) Exercise 6.2: a) Modify the program gausselim.py in Example 6.1 to incorporate partial pivot- ing (or you can write your own program from scratch if you prefer). Run your program and demonstrate that it gives the same answers as the original program when applied to Eq. (6.1). b) Modify the program to solve the equations in (6.17) and show that it can find the solution to these as well, even though Gaussian elimination without pivoting Answer: 61.619,-0.424, -1.238 1.3317 fails. don't do it wlo pivoting from numpy import array, empty A = array([[ 2, 1, 4, 1], [ 3, 4, -1, -1], [1, -4, 1, 5], [2, -2, 1, 3 ]], float) array([ -4, 3, 9, 7 ],float) N = len(v) V = # Gaussian elimination for m in range(N): # Divide by the diagonal element div = A[m,m] A[m, :] /= div v[m] /= div # Now subtract from the lower rows for i in range (m+1,N): mult = A[i,m] A[i, :] -= mult*A [m, :] v[i] -= mult*v [m] # Backsubstitution x = empty(N,float) for m in range (N-1,-1,-1): = for i in range (m+1,N): A[m,i] *x[i] print(x) 0 1 4 1 3 4 -1 -1 1 -4 1 5 2 -2 1 3 -4 3 9 7 (6.17)
Python v3.9 please! I need help with this question.. i have the answer but not sure how to include the pivoting to get the right answer.
gausselim.py example:
eq. (6.17):
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started