Integrals in Python with SciPy and SymPy
Calculate definite and indefinite integrals in Python: numerical integration with scipy.integrate.quad and exact answers with SymPy.
View example →Solve equations, integrals, derivatives and differential equations, fit curves and analyse signals with SymPy, SciPy and NumPy, in runnable examples.
Run Math and Science with Python onlineCalculate definite and indefinite integrals in Python: numerical integration with scipy.integrate.quad and exact answers with SymPy.
View example →Find derivatives in Python: exact first and second derivatives with sympy.diff, evaluation with subs, and a numerical central difference.
View example →Solve equations in Python with sympy.solve: quadratics, equations with Eq, complex roots, exact square roots and systems of equations.
View example →Solve a system of linear equations in Python with numpy.linalg.solve, check the answer with np.allclose and handle singular matrices.
View example →Find the inverse of a matrix in Python with numpy.linalg.inv, check that A times its inverse is the identity, and see why solve is better.
View example →Solve nonlinear equations and systems in Python with scipy.optimize.fsolve: starting guesses, several roots and checking convergence.
View example →Implement the Newton-Raphson method in Python to find a root, printing each iteration so you can see how fast it converges.
View example →Find a root with the bisection method in Python: halve the interval until it is small enough, and count the steps it takes.
View example →Fit a curve to data in Python with scipy.optimize.curve_fit: an exponential decay model, starting guesses, fitted parameters and their errors.
View example →Fit a straight line by least squares in Python with numpy.polyfit and numpy.linalg.lstsq, then measure the fit with R squared.
View example →Interpolate between data points in Python: linear interpolation with numpy.interp and a smooth cubic spline with scipy.interpolate.CubicSpline.
View example →Use the FFT in Python with numpy.fft.rfft and rfftfreq to find the frequencies in a signal, with correctly scaled amplitudes.
View example →Solve ordinary differential equations in Python with scipy.integrate.solve_ivp, compare with the exact solution and handle a second-order ODE.
View example →Find the minimum of a function in Python with scipy.optimize.minimize: starting points, the BFGS method, the Rosenbrock function and bounds.
View example →Run Monte Carlo simulations in Python with NumPy: estimate pi from random points and find dice probabilities by simulating many rolls.
View example →Implement composite Simpson's rule in Python for numerical integration, see how the error shrinks, and compare with scipy.integrate.simpson.
View example →Run a t-test in Python with scipy.stats: an independent two-sample t-test with ttest_ind, a one-sample test with ttest_1samp, and reading the p-value.
View example →