Skip to content

auto_math_lyapunov_stability_4

github-actions[bot] edited this page Jul 20, 2026 · 2 revisions

Snippet from Math-Lyapunov-Stability.md

import numpy as np

def select_lyapunov(state, V_functions):
    """
    Choose Lyapunov function with smallest value.
    
    Args:
        state: Current state vector.
        V_functions: List of candidate Lyapunov functions.
    
    Returns:
        Tuple of (selected_index, V_value).
    """
    values = [V_i(state) for V_i in V_functions]
    min_idx = np.argmin(values)
    return min_idx, values[min_idx]

# Example: Three models with different energy landscapes
def V1(x): return np.linalg.norm(x - np.array([1, 0]))**2
def V2(x): return np.linalg.norm(x - np.array([0, 1]))**2
def V3(x): return np.linalg.norm(x)**2

V_functions = [V1, V2, V3]
state = np.array([0.5, 0.3])

idx, val = select_lyapunov(state, V_functions)
print(f"Selected V_{idx+1}(x) = {val:.3f}")

Clone this wiki locally