Apply scientific Python routines with attention to assumptions and numerical results.

Before starting: Python, NumPy arrays, and basic linear algebra.

Practice project: Solve a small system and check its residual.

Foundation and first practice

  1. Solve and check a small linear system with SciPy

    A numerical solver is easier to trust when you check its answer against the original equation. For A times x equals b, compute the residual A @ x - b. Floating-point arithmetic can produce tiny nonzero residuals, so use an appropriate tolerance. A successful solve does not prove that noisy or ill-conditioned data gives a reliable real-world model.

    Python 3 with NumPy and SciPy installed

    import numpy as np
    from scipy.linalg import solve
    
    a = np.array([[1.0, 1.0], [2.0, -1.0]])
    b = np.array([5.0, 1.0])
    x = solve(a, b)
    print(x)
    print(np.allclose(a @ x, b))
    Check the output
    [2. 3.]
    True

    Make the two rows dependent and observe the solver behavior. Explain why an equation system may not have a unique solution.

Open the SciPy learning path on DevStudyHub · Play coding games on this blog

logoblog

No comments:

Post a Comment

Please do not enter any spam link in the comment box.