```python
import numpy as np
import sympy as sy
```


```python
p   = 3
Nel = 5

t, dt = sy.symbols('t, dt')
knots = (np.arange(Nel + 1 + 2*p) - p)*dt
```


```python
knots
```




    array([-3*dt, -2*dt, -dt, 0, dt, 2*dt, 3*dt, 4*dt, 5*dt, 6*dt, 7*dt, 8*dt],
          dtype=object)




```python
N3 = [[[]], [[], []], [[], [], []], [[], [], [], []]]

# initialization
for i in range(len(knots) - 1):
    N3[0][0].append(1)

# recursion
for i in range(1, p + 1):
    
    pk = i
    
    for j in range(len(knots) - pk - 1):
        for k in range(pk + 1):

            if k == 0:

                N3[i][k].append(sy.expand((t - knots[j])/(knots[j + pk] - knots[j])*N3[i - 1][k][j] + (knots[j + pk + 1] - t)/(knots[j + pk + 1] - knots[j + 1])*0))

            elif k == pk:

                N3[i][k].append(sy.expand((t - knots[j])/(knots[j + pk] - knots[j])*0 + (knots[j + pk + 1] - t)/(knots[j + pk + 1] - knots[j + 1])*N3[i - 1][k - 1][j + 1]))
                
            else:
                
                N3[i][k].append(sy.expand((t - knots[j])/(knots[j + pk] - knots[j])*N3[i - 1][k][j] + (knots[j + pk + 1] - t)/(knots[j + pk + 1] - knots[j + 1])*N3[i - 1][k - 1][j + 1]))
```


```python
N3[3][3][0]
```




    1/6 - t/(2*dt) + t**2/(2*dt**2) - t**3/(6*dt**3)




```python
p   = 2
Nel = 5

t, dt = sy.symbols('t, dt')
knots = (np.arange(Nel + 1 + 2*p) - p)*dt
```


```python
knots
```




    array([-2*dt, -dt, 0, dt, 2*dt, 3*dt, 4*dt, 5*dt, 6*dt, 7*dt],
          dtype=object)




```python
N2 = [[[]], [[], []], [[], [], []]]

# initialization
for i in range(len(knots) - 1):
    N2[0][0].append(1)

# recursion
for i in range(1, p + 1):
    
    pk = i
    
    for j in range(len(knots) - pk - 1):
        for k in range(pk + 1):

            if k == 0:

                N2[i][k].append(sy.expand((t - knots[j])/(knots[j + pk] - knots[j])*N2[i - 1][k][j] + (knots[j + pk + 1] - t)/(knots[j + pk + 1] - knots[j + 1])*0))

            elif k == pk:

                N2[i][k].append(sy.expand((t - knots[j])/(knots[j + pk] - knots[j])*0 + (knots[j + pk + 1] - t)/(knots[j + pk + 1] - knots[j + 1])*N2[i - 1][k - 1][j + 1]))
                
            else:
                
                N2[i][k].append(sy.expand((t - knots[j])/(knots[j + pk] - knots[j])*N2[i - 1][k][j] + (knots[j + pk + 1] - t)/(knots[j + pk + 1] - knots[j + 1])*N2[i - 1][k - 1][j + 1]))
```


```python
N2[2][0][2]
```




    t**2/(2*dt**2)




```python
p   = 1
Nel = 5

t, dt = sy.symbols('t, dt')
knots = (np.arange(Nel + 1 + 2*p) - p)*dt
```


```python
knots
```




    array([-dt, 0, dt, 2*dt, 3*dt, 4*dt, 5*dt, 6*dt], dtype=object)




```python
N1 = [[[]], [[], []]]

# initialization
for i in range(len(knots) - 1):
    N1[0][0].append(1)

# recursion
for i in range(1, p + 1):
    
    pk = i
    
    for j in range(len(knots) - pk - 1):
        for k in range(pk + 1):

            if k == 0:

                N1[i][k].append(sy.expand((t - knots[j])/(knots[j + pk] - knots[j])*N1[i - 1][k][j] + (knots[j + pk + 1] - t)/(knots[j + pk + 1] - knots[j + 1])*0))

            elif k == pk:

                N1[i][k].append(sy.expand((t - knots[j])/(knots[j + pk] - knots[j])*0 + (knots[j + pk + 1] - t)/(knots[j + pk + 1] - knots[j + 1])*N1[i - 1][k - 1][j + 1]))
                
            else:
                
                N1[i][k].append(sy.expand((t - knots[j])/(knots[j + pk] - knots[j])*N1[i - 1][k][j] + (knots[j + pk + 1] - t)/(knots[j + pk + 1] - knots[j + 1])*N1[i - 1][k - 1][j + 1]))
```


```python
N1[1][0][1]
```




    t/dt




```python

```

c77fb1aaf3a04631f1c937aa2290d4170697ff89
ipynb
Jupyter Notebook
02_HybridModelling/21_HyCho_pp_forms.ipynb
ratnania/mhd
89f383695075aa26fc805ffbf6ba458f0cdd6f4e
MIT
2018-04-13T15:35:21.000Z
2019-10-29T09:39:13.000Z
02_HybridModelling/21_HyCho_pp_forms.ipynb
ratnania/mhd
89f383695075aa26fc805ffbf6ba458f0cdd6f4e
MIT
02_HybridModelling/21_HyCho_pp_forms.ipynb
ratnania/mhd
89f383695075aa26fc805ffbf6ba458f0cdd6f4e
MIT
2018-10-19T10:53:15.000Z
2018-10-19T10:53:15.000Z
Qwen/Qwen-72B
1. YES
2. YES