Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8938821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:43:10+00:00 2026-06-15T10:43:10+00:00

I have implemented a Gauss-algorithm without pivoting. import matplotlib.pyplot as plt import numpy as

  • 0

I have implemented a Gauss-algorithm without pivoting.

import matplotlib.pyplot as plt
import numpy as np
import scipy as sp

def gauss_solve(A,b):
    """
    args: coefficient matrix A of dim(nxn) and vector b of dim(n) 
    of a system of linear equations with n unknowns.
    note: no zeroes on the main diagonal of A allowed!

    returns: vector x of dim(n) which solves the SLE
    """
    while np.ndim(A) != 2 or A.shape[0] != A.shape[1]:
        A = input(["The matrix you entered is not square, specify new input matrix A: "])
#    print "A ok."
    while np.ndim(b) != 1 or A.shape[1] != b.shape[0]:
        b = input(["The dimension of the constant vector b is incorrect, please specify new input vector b"])
#    print "b ok."
    if np.linalg.det(A) == 0:
        return "This linear system doesn't have a single unique solution."
#    print "System does have solution: "
    n = len(b)
    for i in xrange(n): # create triangular matrix
        if A[i,i] == 0:
            return "This implementation doesn't allow A to have zero entries on the main diagonal."
        A[i] = A[i]/float(A[i,i])
        b[i] = b[i]/float(A[i,i])
        for l in xrange(i+1,n):
            A[l] -= A[i]*A[l,i]
            b[l] -= b[i]*A[l,i]
    r = np.zeros(n) # result
    for i in xrange(n):
        r[-(i+1)] = b[-(i+1)] - np.dot(r,A[-(i+1)])
    return r

def test_gauss():
    m = 10
    e = 0.1
    A = sp.rand(m,m)
#    A,b = np.array([[e,1.],[1.,1.]]),np.array([1.,e])
    b = sp.rand(m)
    print gauss_solve(A,b)
    print "Build-in function says: \n", np.linalg.solve(A,b)

test_gauss()

The test-function can generate random entries for A and b. Everything works perfectly fine I think, but I have a matrix here which causes unexpected results:

A = [[e 1] [1 1]]
b = [1 e]

For e != 1 the analytical solution is

x = [-1 e+1]

But I tried some values for e and I just don’t get the analytical solutions. Even the build in function solve(A,b) fails. The first entry of x for instance is always 0 (though it should be -1, totally independent of e). Can anybody explain why this happens?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:43:12+00:00Added an answer on June 15, 2026 at 10:43 am

    Your parallel updates to A and b are incorrect, since you’re updating b using the new values for A. You need to replace the lines:

    A[i] = A[i]/float(A[i,i])
    b[i] = b[i]/float(A[i,i])
    

    with something like:

    divisor = A[i,i]
    A[i] = A[i]/float(divisor)
    b[i] = b[i]/float(divisor)
    

    and similarly, the lines:

    A[l] -= A[i]*A[l,i]
    b[l] -= b[i]*A[l,i]
    

    with

    multiplier = A[l,i]
    A[l] -= A[i]*multiplier
    b[l] -= b[i]*multiplier
    

    In your original code, the lines for b do nothing (disregarding issues of floating-point precision): the first section of code divides b[i] by 1.0, while the second subtracts 0.0 times b[i] from b[l].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented changing the brightness of an image using uislider in iPhone without
I have implemented the algorithm, but what I am facing is how can I
I have implemented one algorithm (RLSR) which there are two regularization factor. Based on
I have implemented correctly bump's api, and added this code: - (void) configureBump {
I have implemented pagination to my data, but the problem is I only have
I have implemented a table view with multiple threads. Currently when a user taps
I have implemented a test method with Jersey to run on my Google AppEngine
I have implemented Facebook into my app but now I find that whenever I
I have implemented clean URLs using the following in my .htaccess RewriteEngine on RewriteCond
I have implemented a very basic sign up using email address+name, although I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.