Skip to content

Instantly share code, notes, and snippets.

@nbelakovski
nbelakovski / collocation.py
Last active June 22, 2025 16:23
Collocation with a monomial basis and multiple elements
import numpy as np
from scipy.optimize import root
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt
# Set up our approximation functions and a function to generate the system of equations we'll need
def xtilde(t, a0_to_an):
degree = len(a0_to_an) - 1
terms = [a0_to_an[i] * t**i for i in range(degree+1)]
return sum(terms)