# Change of basis matrices

## A1

#### Code to compute the change of basis matrix $A_1$

We begin by importing some stuff and defining our functions:


```python
import numpy as np
from IPython.display import display, Math
import sympy
from sympy import *
from sympy.functions.special.tensor_functions import KroneckerDelta

# Initialize the session
init_session(quiet=True)

# I am using the dev version of sympy
print("Using sympy version", sympy.__version__)

# Define our symbols
z, n = symbols('z n')
```

    
    Using sympy version 1.3



```python
def ptilde(n, z):
    """Return the n^th term in the polynomial basis."""
    return z ** n
```


```python
def Coefficient(expression, term):
    """Return the coefficient multiplying `term` in `expression`."""
    # Get the coefficient
    coeff = expression.coeff(term)
    # Set any non-constants in this coefficient to zero. If the coefficient
    # is not a constant, this is not the term we are interested in!
    coeff = coeff.subs(z, 0)
    return coeff
```


```python
def A1(N):
    """Return the change of basis matrix A1."""
    res = zeros(N + 1, N + 1)
    for i in range(N + 1):
        for j in range(N + 1):
            res[i, j] = (-1) ** (i + 1) * binomial(j, i)
    return res
```

We can finally evaluate the change of basis matrix for $N = 5$:


```python
A1(5)
```




$$\left[\begin{matrix}-1 & -1 & -1 & -1 & -1 & -1\\0 & 1 & 2 & 3 & 4 & 5\\0 & 0 & -1 & -3 & -6 & -10\\0 & 0 & 0 & 1 & 4 & 10\\0 & 0 & 0 & 0 & -1 & -5\\0 & 0 & 0 & 0 & 0 & 1\end{matrix}\right]$$



■

## A2

#### Code to compute the change of basis matrix $A_2$


```python
def gtilde(n, z):
    """Return the n^th term in the Green's basis."""
    if n == 0:
        return 1 + 0 * z
    elif n == 1:
        return z
    else:
        return (n + 2) * z ** n - n * z ** (n - 2)
```


```python
def p_G(n, N):
    """Return the polynomial basis representation of the Green's polynomial `g`."""
    g = gtilde(n, z)
    res = [g.subs(z, 0)]
    for n in range(1, N + 1):
        res.append(Coefficient(g, ptilde(n, z)))
    return res
```


```python
def A2(N):
    """Return the change of basis matrix A2. The columns of the **inverse** of this matrix are given by `p_G`."""
    res = zeros(N + 1, N + 1)
    for n in range(N + 1):
        res[n] = p_G(n, N)
    return res.inv()
```


```python
A2(5)
```




$$\left[\begin{matrix}1 & 0 & \frac{1}{2} & 0 & \frac{1}{3} & 0\\0 & 1 & 0 & \frac{3}{5} & 0 & \frac{3}{7}\\0 & 0 & \frac{1}{4} & 0 & \frac{1}{6} & 0\\0 & 0 & 0 & \frac{1}{5} & 0 & \frac{1}{7}\\0 & 0 & 0 & 0 & \frac{1}{6} & 0\\0 & 0 & 0 & 0 & 0 & \frac{1}{7}\end{matrix}\right]$$



■

## A

#### Code to compute the full change of basis matrix $A$

This is now easy: it's just the dot product of the previous two matrices.


```python
def A(N):
    """Return the full change of basis matrix."""
    return A2(N) * A1(N)
```


```python
A(5)
```




$$\left[\begin{matrix}-1 & -1 & - \frac{3}{2} & - \frac{5}{2} & - \frac{13}{3} & - \frac{23}{3}\\0 & 1 & 2 & \frac{18}{5} & \frac{32}{5} & \frac{80}{7}\\0 & 0 & - \frac{1}{4} & - \frac{3}{4} & - \frac{5}{3} & - \frac{10}{3}\\0 & 0 & 0 & \frac{1}{5} & \frac{4}{5} & \frac{15}{7}\\0 & 0 & 0 & 0 & - \frac{1}{6} & - \frac{5}{6}\\0 & 0 & 0 & 0 & 0 & \frac{1}{7}\end{matrix}\right]$$



LaTeX representation for the paper:


```python
print(latex(A(5)))
```

    \left[\begin{matrix}-1 & -1 & - \frac{3}{2} & - \frac{5}{2} & - \frac{13}{3} & - \frac{23}{3}\\0 & 1 & 2 & \frac{18}{5} & \frac{32}{5} & \frac{80}{7}\\0 & 0 & - \frac{1}{4} & - \frac{3}{4} & - \frac{5}{3} & - \frac{10}{3}\\0 & 0 & 0 & \frac{1}{5} & \frac{4}{5} & \frac{15}{7}\\0 & 0 & 0 & 0 & - \frac{1}{6} & - \frac{5}{6}\\0 & 0 & 0 & 0 & 0 & \frac{1}{7}\end{matrix}\right]


■

## Example

#### Compute the Green's basis for quadratic limb darkening


```python
u1, u2 = symbols("u_1 u_2")
A(2) * Matrix([-1, u1, u2])
```




$$\left[\begin{matrix}- u_{1} - \frac{3 u_{2}}{2} + 1\\u_{1} + 2 u_{2}\\- \frac{u_{2}}{4}\end{matrix}\right]$$



■

49cd31302c6344486758beea6eba8c21a36716c2
ipynb
Jupyter Notebook
proofs/A.ipynb
langfzac/Limbdark.jl
a6a30c52e14686a9a01d7b4437f4f171c9c53a24
MIT
2019-05-08T09:03:56.000Z
2021-02-14T20:53:23.000Z
proofs/A.ipynb
langfzac/Limbdark.jl
a6a30c52e14686a9a01d7b4437f4f171c9c53a24
MIT
2018-04-23T20:41:25.000Z
2019-05-02T01:50:19.000Z
proofs/A.ipynb
langfzac/Limbdark.jl
a6a30c52e14686a9a01d7b4437f4f171c9c53a24
MIT
2019-05-15T08:06:04.000Z
2020-02-24T19:11:47.000Z
Qwen/Qwen-72B
1. YES
2. YES