# HW 1

## Imports


```python
import sympy
import numpy
import plotly.graph_objects as go
```

## Problem 1


```python
zeta = sympy.symbols('zeta')
```


```python
lam = sympy.Matrix([
    [sympy.cosh(zeta), -sympy.sinh(zeta), 0, 0],
    [-sympy.sinh(zeta), sympy.cosh(zeta), 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 1],
])

lam
```




$\displaystyle \left[\begin{matrix}\cosh{\left(\zeta \right)} & - \sinh{\left(\zeta \right)} & 0 & 0\\- \sinh{\left(\zeta \right)} & \cosh{\left(\zeta \right)} & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{matrix}\right]$




```python
eta = sympy.Matrix([
    [-1, 0, 0, 0],
    [0, 1, 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 1],
])

eta
```




$\displaystyle \left[\begin{matrix}-1 & 0 & 0 & 0\\0 & 1 & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{matrix}\right]$




```python
sympy.simplify(lam.transpose() * eta * lam)
```




$\displaystyle \left[\begin{matrix}-1 & 0 & 0 & 0\\0 & 1 & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{matrix}\right]$




```python
sympy.simplify(eta * lam)
```




$\displaystyle \left[\begin{matrix}- \cosh{\left(\zeta \right)} & \sinh{\left(\zeta \right)} & 0 & 0\\- \sinh{\left(\zeta \right)} & \cosh{\left(\zeta \right)} & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{matrix}\right]$




```python
print(lam.transpose()._repr_latex_())
```

    $\displaystyle \left[\begin{matrix}\cosh{\left(\zeta \right)} & - \sinh{\left(\zeta \right)} & 0 & 0\\- \sinh{\left(\zeta \right)} & \cosh{\left(\zeta \right)} & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{matrix}\right]$


## Problem 2


```python
def star_rad(conf_time: float, rad_0: float) -> float:
    """Surface of star radial coordinate in conformal time"""
    return 0.5 * rad_0 * (1 + numpy.cos(conf_time))

def star_time(conf_time: float, rad_0: float, mass: float = 1) -> float:
    """Surface of star time coordinate in conformal time"""
    return numpy.sqrt((rad_0 ** 3) / (8 * mass)) * (conf_time + numpy.sin(conf_time))

def a_m(rad_0: float, mass: float = 1) -> float:
    return numpy.sqrt(rad_0 ** 3 / (2 * mass))

def co_rad(conf_time: float, rad_0: float, mass: float = 1) -> float:
    return 0.5 * a_m(rad_0, mass=mass) * (1 + numpy.cos(conf_time))

def co_time(conf_time: float, rad_0: float, mass: float = 1) -> float:
    return 0.5 * a_m(rad_0, mass=mass) * (conf_time + numpy.sin(conf_time))
```


```python
conf_times = numpy.arange(0, numpy.pi, 0.01)
mass_fracs = [0.1, 0.25, 0.5, 1.0]
r_full = 5.0
r_0s = numpy.array(mass_fracs) ** (1/3) * r_full

rads = []
times = []

for r_0, mass_frac in zip(r_0s, mass_fracs):
    print(r_0)
    rads.append(star_rad(conf_times, r_0))
    times.append(star_time(conf_times, r_0, mass=mass_frac))
```

    2.3207944168063896
    3.149802624737183
    3.968502629920499
    5.0



```python
fig = go.Figure()


for r_0, r, t in zip(r_0s, rads, times):
    fig.add_trace(go.Scatter(x=r, y=t, mode='lines', name='{:.2f}'.format(r_0)))

fig.update_layout(
                  yaxis_range=[0,25],
                  xaxis_range=[0,6],
                  width=600,
                  height=600,
                  showlegend=True,
                  title_text=r'$\text{Oppenheimer Snyder }(\tau, R)$', 
                  title_x=0.5,
                  xaxis_title=r'$R / M$',
                  yaxis_title=r'$\tau/M$')
fig.show()
```


<div>                            <div id="80c1a3f5-1544-417e-9b67-7caf40f62e04" class="plotly-graph-div" style="height:600px; width:600px;"></div>                    </div>



```python
fig.write_image('hw1-prob2.pdf')
```


```python

```


```python

```


```python

```

83a7a6409bb07e1b0851184a4a6460c8c3c9bac2
ipynb
Jupyter Notebook
notebooks/homework-1.ipynb
JWKennington/CourseNR
c0f62c0e129fd44c3b1c006fce62e4528e59cd8b
MIT
notebooks/homework-1.ipynb
JWKennington/CourseNR
c0f62c0e129fd44c3b1c006fce62e4528e59cd8b
MIT
notebooks/homework-1.ipynb
JWKennington/CourseNR
c0f62c0e129fd44c3b1c006fce62e4528e59cd8b
MIT
Qwen/Qwen-72B
1. YES
2. YES