```python
import sympy as sp
from sympy.abc import m,n,k,x,y

sp.init_printing()
%matplotlib inline
%config InlineBackend.figure = "retina"
```

# Math HW 2B -- Green's Function

## 1.3 Hands on 🙌


```python
λ = sp.symbols("λ")

# construct your green's function
eigen_functions_mul = sp.sin(n * sp.pi * y) * sp.sin(n * sp.pi * x) \
    / (k**2 - n**2 * sp.pi**2)
greens_function     = 2 * sp.Sum(eigen_functions_mul, (n, 1, m))
greens_function
```

Substitution of variables

$$
    y = 0.5 \\
    k = 0.2 \\
    m = 10   
$$


```python
# substitution in SymPy ... as easy as using a dictionary
greens_function_1 = greens_function.subs({
    y : 0.5,
    k : 0.2, 
    m : 10   # n = 1 ~ 10
})
greens_function_1
```

Ordinary plots, through `matplotlib`


```python
# Sympy plot automatically integrate the matplotlib function
sp.plot(greens_function_1, (x, 0, 1));
```

Sympy is very proud of their self-sufficiency design. It is Python-based and lightweight <font size=-2>(SymPy only depends on mpmath, a pure Python library for arbitrary floating point arithmetic, making it easy to use -- Quoted from Sympy)</font>. 

It means it should has its own plotting design! Let's see.  


```python
# plotting in Sympy
sp.textplot(greens_function_1, 0, 1)
```

          0 |  \                                                    /
            |   \                                                  / 
            |    ..                                              ..  
            |      \                                            /    
            |       ..                                        ..     
            |         \                                      /       
            |          ..                                  ..        
            |            \                                /          
    -0.1201 | ------------..----------------------------..-----------
            |               \                          /             
            |                ..                      ..              
            |                  \                    /                
            |                   ..                ..                 
            |                     \              /                   
            |                      \            /                    
            |                       ..        ..                     
            |                         \      /                       
    -0.2403 |                          ......                        
              0                      0.5                        1


Cuuuute! 🤩🤩🤩

### Exploration n


```python
def plot_helper(y, k, m):
    # construct your green's function
    eigen_functions_mul = sp.sin(n * sp.pi * y) * sp.sin(n * sp.pi * x) \
        / (k**2 - n**2 * sp.pi**2)
    greens_function     = 2 * sp.Sum(eigen_functions_mul, (n, 1, m))
    
    sp.textplot(
        greens_function.subs({
            y : y,
            k : k, 
            m : m  
        }),
        0, 1
    )
```


```python
from ipywidgets import interact
import ipywidgets as widgets

interact(
    plot_helper, 
    y=0.5,
    k=0.2,
    m=widgets.IntSlider(min=1, max=100, step=1, value=10),
)
```


<p>Failed to display Jupyter Widget of type <code>interactive</code>.</p>
<p>
  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean
  that the widgets JavaScript is still loading. If this message persists, it
  likely means that the widgets JavaScript library is either not installed or
  not enabled. See the <a href="https://ipywidgets.readthedocs.io/en/stable/user_install.html">Jupyter
  Widgets Documentation</a> for setup instructions.
</p>
<p>
  If you're reading this message in another frontend (for example, a static
  rendering on GitHub or <a href="https://nbviewer.jupyter.org/">NBViewer</a>),
  it may mean that your frontend doesn't currently support widgets.
</p>






    <function __main__.plot_helper(y, k, m)>



#### Normal Plotting


```python
def plot_helper_normal(y, k, m):
    # construct your green's function
    eigen_functions_mul = sp.sin(n * sp.pi * y) * sp.sin(n * sp.pi * x) \
        / (k**2 - n**2 * sp.pi**2)
    greens_function     = 2 * sp.Sum(eigen_functions_mul, (n, 1, m))
    
    sp.plot(
        greens_function.subs({
            y : y,
            k : k, 
            m : m  
        }),
        (x, 0, 1)
    )
```


```python

```

15d9d6bcf5e6fd41d62d3b89fb6929e70f2f4160
ipynb
Jupyter Notebook
Math HW 2B -- Green's Function Crazy.ipynb
jibanCat/math_homework
228fd61a84d03cdd8944d348e98662f1033e97ef
MIT
Math HW 2B -- Green's Function Crazy.ipynb
jibanCat/math_homework
228fd61a84d03cdd8944d348e98662f1033e97ef
MIT
Math HW 2B -- Green's Function Crazy.ipynb
jibanCat/math_homework
228fd61a84d03cdd8944d348e98662f1033e97ef
MIT
Qwen/Qwen-72B
1. YES
2. YES