<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python on Chen Kai Blog</title><link>https://www.chenk.top/en/tags/python/</link><description>Recent content in Python on Chen Kai Blog</description><generator>Hugo</generator><language>en</language><lastBuildDate>Mon, 15 Apr 2024 09:00:00 +0000</lastBuildDate><atom:link href="https://www.chenk.top/en/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Ordinary Differential Equations (18): Frontiers and Series Finale</title><link>https://www.chenk.top/en/ode/18-advanced-topics-summary/</link><pubDate>Mon, 15 Apr 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/18-advanced-topics-summary/</guid><description>&lt;p>&lt;strong>The journey ends here.&lt;/strong> Eighteen chapters ago we picked up a falling apple. Today we&amp;rsquo;re going to finish in the same vein in which we began — by treating ODEs as the &lt;em>universal language of change&lt;/em> — but standing on a much taller mountain.&lt;/p>
&lt;p>This chapter does three things. First, it surveys four active research frontiers that are reshaping how we &lt;em>model&lt;/em> dynamical systems: Neural ODEs, delay equations, stochastic differential equations, and fractional calculus. Second, it reviews the entire series with a problem-solving flowchart and a chapter-by-chapter map. Third, it draws explicit connections from the classical theory you have just mastered to modern machine learning — the place where ODEs are most alive in 2025.&lt;/p></description></item><item><title>Ordinary Differential Equations (17): Physics and Engineering Applications</title><link>https://www.chenk.top/en/ode/17-physics-engineering-applications/</link><pubDate>Fri, 29 Mar 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/17-physics-engineering-applications/</guid><description>&lt;p>&lt;strong>Differential equations are not a pure mathematical game — they are the language for understanding the physical world.&lt;/strong> From celestial motion to circuit response, from a swinging pendulum to vortex shedding behind a bridge cable, every dynamical system &amp;ldquo;speaks&amp;rdquo; ODE.&lt;/p>
&lt;p>This chapter is a deliberate tour through five canonical applications. Each one will pay back the entire ODE toolkit we built in chapters 1-16: phase planes, eigenvalues, Laplace transforms, modal analysis, conservation laws, numerical integration, control. None of the examples is a &amp;ldquo;toy&amp;rdquo; — they are all genuine working physics, written tightly so that the structure remains visible.&lt;/p></description></item><item><title>Ordinary Differential Equations (16): Fundamentals of Control Theory</title><link>https://www.chenk.top/en/ode/16-control-theory/</link><pubDate>Tue, 12 Mar 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/16-control-theory/</guid><description>&lt;p>&lt;strong>When you steer a car you constantly correct based on lane position. A thermostat compares room temperature with the setpoint and adjusts a heater. A rocket gimbal nudges its thrust vector to keep the booster vertical.&lt;/strong> Strip away the hardware and the same idea remains: &lt;em>measure, compare, act&lt;/em>. Control theory is the mathematics of that loop — and its native language is the ordinary differential equation.&lt;/p>
&lt;p>This chapter shows how the entire ODE toolkit — Laplace transforms (Ch 4), linear systems (Ch 6), eigenvalue stability (Ch 7), nonlinear stability (Ch 8) — collapses into a single unified discipline whose job is no longer to &lt;em>describe&lt;/em> dynamics, but to &lt;em>design&lt;/em> them.&lt;/p></description></item><item><title>Ordinary Differential Equations (15): Population Dynamics</title><link>https://www.chenk.top/en/ode/15-population-dynamics/</link><pubDate>Sat, 24 Feb 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/15-population-dynamics/</guid><description>&lt;p>&lt;strong>Why do lynx and snowshoe hare populations cycle with eerie regularity over a 10-year period?&lt;/strong> Why does introducing a single new species sometimes collapse an entire ecosystem? Why do similar competitors sometimes coexist and sometimes drive each other extinct? The answers are not in the species; they are in the &lt;em>equations&lt;/em> relating the species. This chapter walks through the canonical models of mathematical ecology: from the single-population logistic and Allee models to multi-species competition, predator-prey oscillations, age structure, and spatial spread.&lt;/p></description></item><item><title>Ordinary Differential Equations (14): Epidemic Models and Epidemiology</title><link>https://www.chenk.top/en/ode/14-epidemiology/</link><pubDate>Wed, 07 Feb 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/14-epidemiology/</guid><description>&lt;p>&lt;strong>In early 2020 the entire world watched a small system of ordinary differential equations decide policy.&lt;/strong> &amp;ldquo;Flatten the curve&amp;rdquo; was not a slogan; it was the intuition of a specific equation. &lt;em>Herd immunity&lt;/em> was not a guess; it was the threshold &lt;span class="math-inline">$1 - 1/R_0$&lt;/span>
 derived in a single line. The SIR model — four lines of math, written down in 1927 by Kermack and McKendrick — turned out to be precise enough to drive trillion-dollar decisions.&lt;/p></description></item><item><title>Ordinary Differential Equations (13): Introduction to Partial Differential Equations</title><link>https://www.chenk.top/en/ode/13-pde-introduction/</link><pubDate>Sun, 21 Jan 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/13-pde-introduction/</guid><description>&lt;p>&lt;strong>Once a quantity depends on more than one variable, the ODE world splinters into a vastly richer one: partial differential equations.&lt;/strong> Heat in a metal rod is a function of position &lt;em>and&lt;/em> time; a vibrating string moves in space &lt;em>and&lt;/em> time; a steady electrostatic potential lives in three spatial dimensions. ODE techniques become tools, not solutions — separation of variables turns one PDE into a &lt;em>family&lt;/em> of ODEs, the eigenvalues of those ODEs become the spectrum of the operator, and superposition stitches everything back together.&lt;/p></description></item><item><title>Ordinary Differential Equations (12): Boundary Value Problems</title><link>https://www.chenk.top/en/ode/12-boundary-value-problems/</link><pubDate>Thu, 04 Jan 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/12-boundary-value-problems/</guid><description>&lt;p>An initial value problem hands you a starting state and asks you to march forward. A boundary value problem (BVP) hands you partial information at two different points and asks you to find a path that fits both. The change is small in wording, large in consequence: BVPs can have a unique solution, no solution at all, or infinitely many. They demand a fundamentally different toolkit — one that is iterative, global, and intimately connected to linear algebra.&lt;/p></description></item><item><title>Ordinary Differential Equations (11): Numerical Methods</title><link>https://www.chenk.top/en/ode/11-numerical-methods/</link><pubDate>Mon, 18 Dec 2023 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/11-numerical-methods/</guid><description>&lt;p>Almost every interesting differential equation in science and engineering resists a closed-form solution. Nonlinear vector fields, variable coefficients, and thousands of coupled state variables — pen and paper fail long before the problem does. Numerical integration is the key. This chapter builds, evaluates, and compares a small set of algorithms that can solve almost any ODE you&amp;rsquo;ll encounter and provides diagnostics to spot when an integrator is misleading you.&lt;/p>
&lt;p>&lt;figure class="article-figure">
 &lt;img src="https://blog-pic-ck.oss-cn-beijing.aliyuncs.com/posts/en/ode/11-numerical-methods/illustration_1.png" alt="Ordinary Differential Equations (11): Numerical Methods — Chapter overview" loading="lazy" decoding="async" class="content-image">
 
&lt;/figure>
&lt;/p></description></item><item><title>Ordinary Differential Equations (10): Bifurcation Theory</title><link>https://www.chenk.top/en/ode/10-bifurcation-theory/</link><pubDate>Fri, 01 Dec 2023 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/10-bifurcation-theory/</guid><description>&lt;p>A lake stays clear for decades, then turns murky in a single season. A power grid hums along stably, then trips into a cascading blackout in seconds. A column under slowly increasing load is straight, straight, straight — and then suddenly buckles.&lt;/p>
&lt;p>These are not prediction failures. The universe is doing exactly what dynamical systems theory says it must: cross a &lt;strong>bifurcation&lt;/strong>. When a parameter drifts past a critical value, the topology of phase space rearranges, and what was once impossible becomes inevitable. This chapter classifies these rearrangements. There are only a few, and once you see the catalog, you&amp;rsquo;ll spot them everywhere.&lt;/p></description></item><item><title>Ordinary Differential Equations (1): Origins and Intuition</title><link>https://www.chenk.top/en/ode/01-origins-and-intuition/</link><pubDate>Sat, 01 Jul 2023 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/ode/01-origins-and-intuition/</guid><description>&lt;p>&lt;strong>Everything around you is changing.&lt;/strong> Coffee cools, populations grow, pendulums swing, viruses spread, stocks oscillate, planets orbit. None of these systems are described by &lt;em>what something equals&lt;/em> — they are described by &lt;em>how fast something changes&lt;/em>. That second mode of description is what differential equations are for, and learning to read them is, quite literally, learning to read the language physics and biology are written in.&lt;/p>
&lt;p>This chapter rebuilds your intuition from scratch. We start with a single cup of coffee, derive the same equation that governs radioactive decay and capacitor discharge, then climb upward to direction fields, classification, and the existence-and-uniqueness theorem that tells you when an ODE has a sensible answer at all.&lt;/p></description></item><item><title>Python Engineering (8): Performance — Profiling, Caching, and Knowing When to Stop</title><link>https://www.chenk.top/en/python-engineering/08-performance-and-profiling/</link><pubDate>Wed, 27 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/08-performance-and-profiling/</guid><description>&lt;p>Donald Knuth&amp;rsquo;s famous quote is often half-remembered. The full version is: &amp;ldquo;We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.&amp;rdquo; The second sentence is the key. Performance work isn&amp;rsquo;t about making everything fast; it&amp;rsquo;s about finding the 3% that matters and making that fast.&lt;/p>
&lt;p>This article is about finding that 3%. You&amp;rsquo;ll learn to profile first, optimize second, and measure the impact of each change.&lt;/p></description></item><item><title>Python Engineering (7): Packaging — From pip install to PyPI</title><link>https://www.chenk.top/en/python-engineering/07-packaging-and-distribution/</link><pubDate>Sun, 24 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/07-packaging-and-distribution/</guid><description>&lt;p>You wrote a useful utility. A colleague asks you to share it. You zip the folder and email it. They unzip it, run &lt;code>python main.py&lt;/code>, and get &lt;code>ModuleNotFoundError&lt;/code> because they do not have the dependencies. Then they install the dependencies, but the wrong versions. Then they have Python 3.8 and your f-string walrus operators do not parse.&lt;/p>
&lt;p>Proper packaging eliminates all of this. With &lt;code>pip install your-tool&lt;/code>, everything just works: correct dependencies, correct versions, and a clean CLI command.&lt;/p></description></item><item><title>Python Engineering (6): Concurrency — Threads, Processes, and asyncio</title><link>https://www.chenk.top/en/python-engineering/06-concurrency/</link><pubDate>Thu, 21 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/06-concurrency/</guid><description>&lt;p>Your script downloads 100 files one at a time. Each download takes 2 seconds, mostly waiting for the server to respond. Total time: 200 seconds. Your CPU is idle for 99% of that time, wasting compute and money on network latency. Concurrency can fix this.&lt;/p>
&lt;p>Python has three concurrency models, each designed for different problems. Choosing the wrong one can make your code slow or full of race conditions. This article explains when to use each.&lt;/p></description></item><item><title>Python Engineering (5): I/O, Serialization, and Data Formats</title><link>https://www.chenk.top/en/python-engineering/05-io-and-serialization/</link><pubDate>Tue, 19 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/05-io-and-serialization/</guid><description>&lt;p>Most programs are just plumbing between data formats. Read a CSV, transform it, write JSON. Load a config file, validate it, pass settings to the application. Every Python developer writes this code, and most of them get encoding, path handling, or serialization subtleties wrong at least once.&lt;/p>
&lt;p>This article covers every common I/O pattern in Python, from basic file reading to columnar data formats, with a focus on the pitfalls that waste your time.&lt;/p></description></item><item><title>Python Engineering (4): Type Hints, Linting, and Code Quality</title><link>https://www.chenk.top/en/python-engineering/04-type-hints-and-linting/</link><pubDate>Sun, 17 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/04-type-hints-and-linting/</guid><description>&lt;p>Code reviews should be about logic and design, not about whether someone used single quotes or double quotes. Formatting debates are a waste of engineering time. The solution is to let machines handle style and let humans focus on correctness.&lt;/p>
&lt;p>This article covers three layers of automated code quality: type hints catch logical errors before runtime, linters catch style violations and common bugs, and pre-commit hooks enforce everything automatically on every commit.&lt;/p></description></item><item><title>Python Engineering (3): Testing — pytest, Fixtures, and the Confidence Loop</title><link>https://www.chenk.top/en/python-engineering/03-testing-and-debugging/</link><pubDate>Thu, 14 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/03-testing-and-debugging/</guid><description>&lt;p>You change one line and three unrelated features break. You refactor a function and spend two hours manually clicking through the app to check if everything still works. You deploy on Friday and get paged at midnight. All of these are symptoms of the same disease: no tests.&lt;/p>
&lt;p>Tests are not bureaucracy. They are the fastest way to know that your code does what you think it does. A good test suite runs in seconds and catches the bugs that would take hours to find manually.&lt;/p></description></item><item><title>Python Engineering (2): Project Structure — From Script to Package</title><link>https://www.chenk.top/en/python-engineering/02-project-structure/</link><pubDate>Tue, 12 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/02-project-structure/</guid><description>&lt;p>Every project starts as a single file. You write &lt;code>main.py&lt;/code>, it works, you add features, and one day you realize you have 1,500 lines in one file with functions that call other functions that depend on globals defined 800 lines above. The code works, but nobody (including future you) can understand it.&lt;/p>
&lt;p>The jump from script to package is the first real engineering decision in a Python project. Get it right early, and testing, packaging, and deployment become easier. Get it wrong, and you&amp;rsquo;ll spend weeks untangling circular imports.&lt;/p></description></item><item><title>Python Engineering (1): Environment Setup — pyenv, venv, and Dependency Hell</title><link>https://www.chenk.top/en/python-engineering/01-environment-and-toolchain/</link><pubDate>Sun, 10 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/01-environment-and-toolchain/</guid><description>&lt;p>Every Python developer has lived through this moment: you run a script on your colleague&amp;rsquo;s machine and it crashes because they have Python 3.8 while you wrote it on 3.11. Or worse, you &lt;code>pip install&lt;/code> something globally and break a completely unrelated project. Python&amp;rsquo;s environment story is powerful once you understand it, but the default experience is a minefield.&lt;/p>
&lt;p>This article walks through the entire toolchain from scratch. By the end, you&amp;rsquo;ll have a reproducible, isolated, and version-pinned setup that works the same way on every machine.&lt;/p></description></item></channel></rss>