Differentiating and setting the result to zero solves textbook optimization. With several variables, constraints, or a function without a tractable derivative, that calculation breaks down. We will see minimize, SLSQP and bounds from scipy.optimize, local minima, and global search with differential_evolution.
The classic pendulum period formula only holds for small oscillations, and the exact equation has no closed-form solution. With SciPy’s solve_ivp, we measure the real period and solve stiff systems, Lotka-Volterra, falling with drag, and consecutive reactions.
The Gaussian function has no elementary antiderivative, and that is a theorem of Liouville. When the antiderivative does not exist, or all you have is a table of measurements, the way forward is numerical: quad, trapezoid and Simpson, from scipy.integrate, with the care each one demands.
Is the reactor temperature rising too fast? The question is a derivative, but all we have are numbers in a table. We will see finite differences, numpy.gradient and scipy.differentiate, and why shrinking the step does not always improve the derivative, because of rounding and noise.
From the pH of a weak acid to the volume of a real gas and the friction factor of a pipe: three equations that chemistry and engineering use every day and that only have a useful numerical solution. We solve all three with brentq and numpy.roots and rebuild the Moody chart.
Where is Halley’s Comet on any given date? The answer requires solving Kepler’s equation, which has no closed form. With SciPy’s newton and brentq, we locate the comet, make the law of areas visible, and compute the range of a projectile with air resistance.
In Kepler’s equation, the unknown appears both inside and outside a sine, and no algebra isolates it. For cases like this, SciPy approximates the root. We will see bisection and brentq, Newton’s method and why it can fail, and nonlinear systems with fsolve and root.
Most equations, integrals, and differential equations in real problems have no closed-form solution, and SymPy can’t solve them. This 13-article series shows how NumPy and SciPy tackle these problems: roots, polynomials, numerical calculus, optimization, and FFT.
We have already written here on the site about the concepts of limit and derivative and how we can do the related computations with Python. Continuing our journey through calculus, in this article we will see how to work with integrals using SymPy and SciPy, Python packages. Along the way, we will pick up some notions of numerical methods.
The Olympics are coming to an end… and, besides nostalgia and stories of perseverance, every Olympics leaves behind an enormous amount of data! In this article, we will see how to use Pandas to analyze part of that data, looking at how athletes’ times have evolved in track and field events.
Is it possible to study for the college entrance exam and still learn Python? Of course! And that is one of the goals of the Brazilian Exam Problems category on this site. In it, we use computational tools to analyze and expand problems from the ENEM, Brazil’s national high school exam. In today’s article, we analyze a problem from the 2019 exam. And, along the way, we learn to make 3D and 4D(?!) plots with Matplotlib. All because of a killer brick.
Colorless, made of invisible constituents, and odorless (we hope!). We often forget that we are surrounded by the gases that make up our atmosphere. In this article, we will see how to easily get a list of the main constituents of air with Python and web scraping. We will also do some calculations, such as density and mean molar mass, and, of course, present everything in spectacular plots.
Usain Bolt is considered by many to be the greatest sprinter of all time. In this article, we will see how to use Python to find the speed and acceleration the Jamaican reached in his races. We will also take the chance to discuss mathematical models and the care needed in choosing them and interpreting their results.