# **Optimization - Homework 1**



**Prof. Elías D. Niño-Ruiz, Ph.D.**



*   Nombre del Estudiante: Alejandro Jesús Manotas Marmolejo
*   Código del Estudiante: 200108289



Datasets to employ in this homework:





1.   $u$ wind component (zonal wind component) - [download here](ftp://ftp2.psl.noaa.gov/Datasets/ncep.reanalysis2/pressure/uwnd.2020.nc)
2.   $v$ wind component (meridional wind component) - [download here](ftp://ftp2.psl.noaa.gov/Datasets/ncep.reanalysis2/pressure/vwnd.2020.nc)

Recall that, wind speed reads $w_s = \sqrt{u^2 + v^2}$. 



**Note.** *You can make use of all Jupyter Notebooks, from classes, as needed.*

**High-Order Derivatives for Wind Acceleration**

---


We employed a forward difference approximation for the estimation of wind acceleration in the globe for the NOAA data set, this is:
$$a_{i} = \frac{v_{i+1}-v_i}{h}\,,$$
where $v_i$ is the wind speed at time $i$, and $a_i$ denotes an estimation of the wind acceleration. Note that, by using this formula, we couldn't estimate the acceleration of the last time (because there is no $v_{i+1}$). However, we could do that by using a different formula, for instance, a backward difference approximation could make the work for the last time:
$$a_{i} = \frac{v_{i}-v_{i-1}}{h}\,,$$
in this homework you must:



---


**Exercise 1**

Propose two finite difference approximations for $f'(a)$ as follows:


1.   in the first one, only forward differences can be employed (i.e., $f(a+k\cdot h)$ for $k>0$), and
2.   in the last one, only backward differences can be employed (i.e., $f(a+k\cdot h)$ for $k<0$)

both of them, must be of order $\mathcal{O}(h^5)$. You can use the `sympy` module to make your life easier regarding computations. Show all equations! you can make use of the `Latex` and `display` commands to accomplish this.



**Answer.**

1. Forward differences $(k > 0)$


```
from IPython.display import display, Latex
import sympy as sp
from sympy.parsing.sympy_parser import parse_expr
```


```
def showEquation(s,eqn):
  display(Latex('(Eq. '+str(eqn)+'). \,'+sp.latex(s)+'=0'));
```


```
x = parse_expr('x'); 
fx = parse_expr('f(x)');
a, h = parse_expr('a, h');

eq1 = fx.subs(x,a+h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a+h)
showEquation(eq1,1)

eq2 = fx.subs(x,a+2*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a+2*h)
showEquation(eq2,2)

eq3 = eq2 - 16*eq1
showEquation(eq3,3)
```


(Eq. 1). \,f{\left (a + h \right )} - f{\left (a \right )} - h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{h^{2}}{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{h^{3}}{6} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{h^{4}}{24} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 2). \,f{\left (a + 2 h \right )} - f{\left (a \right )} - 2 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 2 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{4 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{2 h^{4}}{3} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 3). \,f{\left (a + 2 h \right )} - 16 f{\left (a + h \right )} + 15 f{\left (a \right )} + 14 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + 6 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \frac{4 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



```
eq4 = fx.subs(x,a+3*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a+3*h)
showEquation(eq4,4)

eq5 = fx.subs(x,a+6*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a+6*h)
showEquation(eq5,5)

eq6 = (1/16)*eq5 - eq4
showEquation(eq6,6)

eq7 = eq6 - (27/16)*eq3
showEquation(eq7,7)
```


(Eq. 4). \,f{\left (a + 3 h \right )} - f{\left (a \right )} - 3 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{9 h^{2}}{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{9 h^{3}}{2} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{27 h^{4}}{8} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 5). \,f{\left (a + 6 h \right )} - f{\left (a \right )} - 6 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 18 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 36 h^{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 54 h^{4} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 6). \,0.0625 f{\left (a + 6 h \right )} - f{\left (a + 3 h \right )} + 0.9375 f{\left (a \right )} + 2.625 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + 3.375 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + 2.25 h^{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 7). \,0.0625 f{\left (a + 6 h \right )} - f{\left (a + 3 h \right )} - 1.6875 f{\left (a + 2 h \right )} + 27.0 f{\left (a + h \right )} - 24.375 f{\left (a \right )} - 21.0 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 6.75 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



```
eq8 = fx.subs(x,a+4*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a+4*h)
showEquation(eq8,8)

eq9 = fx.subs(x,a+8*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a+8*h)
showEquation(eq9,9)

eq10 = eq9 - 16*eq8
showEquation(eq10,10)

eq11 = eq10 - 64*eq3
showEquation(eq11,11)
```


(Eq. 8). \,f{\left (a + 4 h \right )} - f{\left (a \right )} - 4 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 8 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{32 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{32 h^{4}}{3} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 9). \,f{\left (a + 8 h \right )} - f{\left (a \right )} - 8 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 32 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{256 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{512 h^{4}}{3} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 10). \,f{\left (a + 8 h \right )} - 16 f{\left (a + 4 h \right )} + 15 f{\left (a \right )} + 56 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + 96 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \frac{256 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 11). \,f{\left (a + 8 h \right )} - 16 f{\left (a + 4 h \right )} - 64 f{\left (a + 2 h \right )} + 1024 f{\left (a + h \right )} - 945 f{\left (a \right )} - 840 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 288 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



```
eq12 = eq11 - (128/3)*eq7
showEquation(eq12,12)
```


(Eq. 12). \,f{\left (a + 8 h \right )} - 2.66666666666667 f{\left (a + 6 h \right )} - 16 f{\left (a + 4 h \right )} + 42.6666666666667 f{\left (a + 3 h \right )} + 8.0 f{\left (a + 2 h \right )} - 128.0 f{\left (a + h \right )} + 95.0 f{\left (a \right )} + 56.0 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0


$f'(a)=\frac{-f(a+8h)+2.66666666666667f(a+6h)+16f(a+4h)-42.6666666666667f(a+3h)-8.0f(a+2h)+128.0f(a+h)-95.0f(a)-O(h^5)}{56.0h}$

> Bloque con sangría



2. Backward differences $(k < 0)$


```
fx = parse_expr('f(x)');
a, h = parse_expr('a, h');

eq1 = fx.subs(x,a-h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a-h)
showEquation(eq1,1)

eq2 = fx.subs(x,a-2*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a-2*h)
showEquation(eq2,2)

eq3 = eq2 - 16*eq1
showEquation(eq3,3)
```


(Eq. 1). \,f{\left (a - h \right )} - f{\left (a \right )} + h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{h^{2}}{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \frac{h^{3}}{6} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{h^{4}}{24} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 2). \,f{\left (a - 2 h \right )} - f{\left (a \right )} + 2 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 2 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \frac{4 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{2 h^{4}}{3} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 3). \,- 16 f{\left (a - h \right )} + f{\left (a - 2 h \right )} + 15 f{\left (a \right )} - 14 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + 6 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{4 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



```
eq4 = fx.subs(x,a-3*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a-3*h)
showEquation(eq4,4)

eq5 = fx.subs(x,a-6*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a-6*h)
showEquation(eq5,5)

eq6 = (1/16)*eq5 - eq4
showEquation(eq6,6)

eq7 = eq6 - (27/16)*eq3
showEquation(eq7,7)
```


(Eq. 4). \,f{\left (a - 3 h \right )} - f{\left (a \right )} + 3 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{9 h^{2}}{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \frac{9 h^{3}}{2} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{27 h^{4}}{8} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 5). \,f{\left (a - 6 h \right )} - f{\left (a \right )} + 6 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 18 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + 36 h^{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 54 h^{4} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 6). \,- f{\left (a - 3 h \right )} + 0.0625 f{\left (a - 6 h \right )} + 0.9375 f{\left (a \right )} - 2.625 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + 3.375 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 2.25 h^{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 7). \,27.0 f{\left (a - h \right )} - 1.6875 f{\left (a - 2 h \right )} - f{\left (a - 3 h \right )} + 0.0625 f{\left (a - 6 h \right )} - 24.375 f{\left (a \right )} + 21.0 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 6.75 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



```
eq8 = fx.subs(x,a-4*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a-4*h)
showEquation(eq8,8)

eq9 = fx.subs(x,a-8*h)-sp.series(fx,x=x,x0=a,n=5).subs(x,a-8*h)
showEquation(eq9,9)

eq10 = eq9 - 16*eq8
showEquation(eq10,10)

eq11 = eq10 - 64*eq3
showEquation(eq11,11)
```


(Eq. 8). \,f{\left (a - 4 h \right )} - f{\left (a \right )} + 4 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 8 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \frac{32 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{32 h^{4}}{3} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 9). \,f{\left (a - 8 h \right )} - f{\left (a \right )} + 8 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 32 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \frac{256 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{512 h^{4}}{3} \left. \frac{d^{4}}{d \xi_{1}^{4}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 10). \,- 16 f{\left (a - 4 h \right )} + f{\left (a - 8 h \right )} + 15 f{\left (a \right )} - 56 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + 96 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - \frac{256 h^{3}}{3} \left. \frac{d^{3}}{d \xi_{1}^{3}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



(Eq. 11). \,1024 f{\left (a - h \right )} - 64 f{\left (a - 2 h \right )} - 16 f{\left (a - 4 h \right )} + f{\left (a - 8 h \right )} - 945 f{\left (a \right )} + 840 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} - 288 h^{2} \left. \frac{d^{2}}{d \xi_{1}^{2}}  f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0



```
eq12 = eq11 - (128/3)*eq7
showEquation(eq12,12)
```


(Eq. 12). \,- 128.0 f{\left (a - h \right )} + 8.0 f{\left (a - 2 h \right )} + 42.6666666666667 f{\left (a - 3 h \right )} - 16 f{\left (a - 4 h \right )} - 2.66666666666667 f{\left (a - 6 h \right )} + f{\left (a - 8 h \right )} + 95.0 f{\left (a \right )} - 56.0 h \left. \frac{d}{d \xi_{1}} f{\left (\xi_{1} \right )} \right|_{\substack{ \xi_{1}=a }} + \mathcal{O}\left(h^{5}\right)=0


$f'(a)=\frac{128.0f(a−h)+8.0f(a−2h)-42.6666666666667f(a−3h)+16f(a−4h)+2.66666666666667f(a−6h)-f(a−8h)-95.0f(a)-O(h^5)}{-56.0h}$

**Exercise 2.**

Employ the previous formulas accordingly to estimate the acceleration at **all times** in the first numerical layer (the position 0, the one we choose in classes, this height corresponds to 10 hPa). Compute the mean of accelerations (in the globe) and plot that by using BaseMap (as we done, in classes). You may need to connect Google Drive with your Jupyter Notebook. Set $h=0.25$. Comment as needed.

**Answer.**


```
!apt-get install libgeos-3.5.0
!apt-get install libgeos-dev
!pip install https://github.com/matplotlib/basemap/archive/master.zip
```

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package libgeos-3.5.0
    E: Couldn't find any package by glob 'libgeos-3.5.0'
    E: Couldn't find any package by regex 'libgeos-3.5.0'
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    libgeos-dev is already the newest version (3.6.2-1build2).
    The following package was automatically installed and is no longer required:
      libnvidia-common-440
    Use 'apt autoremove' to remove it.
    0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
    Collecting https://github.com/matplotlib/basemap/archive/master.zip
      Using cached https://github.com/matplotlib/basemap/archive/master.zip
    Requirement already satisfied (use --upgrade to upgrade): basemap==1.2.1 from https://github.com/matplotlib/basemap/archive/master.zip in /usr/local/lib/python3.6/dist-packages
    Requirement already satisfied: matplotlib!=3.0.1,>=1.0.0 in /usr/local/lib/python3.6/dist-packages (from basemap==1.2.1) (3.2.2)
    Requirement already satisfied: numpy>=1.2.1 in /usr/local/lib/python3.6/dist-packages (from basemap==1.2.1) (1.18.5)
    Requirement already satisfied: pyproj>=1.9.3 in /usr/local/lib/python3.6/dist-packages (from basemap==1.2.1) (2.6.1.post1)
    Requirement already satisfied: pyshp>=1.2.0 in /usr/local/lib/python3.6/dist-packages (from basemap==1.2.1) (2.1.0)
    Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from basemap==1.2.1) (1.15.0)
    Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib!=3.0.1,>=1.0.0->basemap==1.2.1) (0.10.0)
    Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib!=3.0.1,>=1.0.0->basemap==1.2.1) (2.8.1)
    Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib!=3.0.1,>=1.0.0->basemap==1.2.1) (1.2.0)
    Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib!=3.0.1,>=1.0.0->basemap==1.2.1) (2.4.7)
    Building wheels for collected packages: basemap
      Building wheel for basemap (setup.py) ... [?25l[?25hdone
      Created wheel for basemap: filename=basemap-1.2.1-cp36-cp36m-linux_x86_64.whl size=121756181 sha256=53a16ce292491e2474f9b96413b900a03836f3b4d9b0d067d22daccf78aa918c
      Stored in directory: /tmp/pip-ephem-wheel-cache-b7f25zsb/wheels/98/4a/fc/ce719b75d97e646645c225f3332b1b217536100314922e9572
    Successfully built basemap



```
pip install netcdf4
```

    Collecting netcdf4
    [?25l  Downloading https://files.pythonhosted.org/packages/09/39/3687b2ba762a709cd97e48dfaf3ae36a78ae603ec3d1487f767ad58a7b2e/netCDF4-1.5.4-cp36-cp36m-manylinux1_x86_64.whl (4.3MB)
    [K     |████████████████████████████████| 4.3MB 3.5MB/s 
    [?25hRequirement already satisfied: numpy>=1.9 in /usr/local/lib/python3.6/dist-packages (from netcdf4) (1.18.5)
    Collecting cftime
    [?25l  Downloading https://files.pythonhosted.org/packages/81/f4/31cb9b65f462ea960bd334c5466313cb7b8af792f272546b68b7868fccd4/cftime-1.2.1-cp36-cp36m-manylinux1_x86_64.whl (287kB)
    [K     |████████████████████████████████| 296kB 35.0MB/s 
    [?25hInstalling collected packages: cftime, netcdf4
    Successfully installed cftime-1.2.1 netcdf4-1.5.4



```
from google.colab import drive
drive.mount('/content/drive')
import pandas as pd
import numpy as np
from netCDF4 import Dataset
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import seaborn as sns
```

    Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly&response_type=code
    
    Enter your authorization code:
    ··········
    Mounted at /content/drive


    /usr/local/lib/python3.6/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
      import pandas.util.testing as tm



```
u_wnd = Dataset('/content/drive/My Drive/uwnd.2020.nc','r');
v_wnd = Dataset('/content/drive/My Drive/vwnd.2020.nc','r');
```


```
lon = u_wnd['lon'][:];
lat = v_wnd['lat'][:];
u = u_wnd['uwnd'];
v = v_wnd['vwnd'];
u = u[:,0,:,:];
v = v[:,0,:,:];
ws = np.sqrt(np.power(u,2)+np.power(v,2))
times, nlat, nlon = np.shape(ws);
ac = np.zeros((times-1,nlat,nlon));
n_ws=len(ws)
```


```
def fwd_diff(f8, f6, f4, f3, f2, f1, f0, h): #Approach from the right
  return (-f8+2.66666666666667*f6+16*f4-42.6666666666667*f3-8.0*f2+128.0*f1-95.0*f0)/(56.0*h)
```


```
def fbwd_diff(f8, f6, f4, f3, f2, f1, f0, h): #Approach from the left
  return (128.0*f1+8.0*f2-42.6666666666667*f3+16*f4+2.66666666666667*f6-f8-95.0*f0)/(-56.0*h)
```


```
for i in range (0,n_ws-8):
  ac[i,:,:] = fwd_diff(ws[i+8,:,:],ws[i+6,:,:],ws[i+4,:,:],ws[i+3,:,:],ws[i+2,:,:],ws[i+1,:,:],ws[i,:,:],0.25);
for i in range (n_ws-7,n_ws-1):
  ac[i,:,:] = fbwd_diff(ws[i-8,:,:],ws[i-6,:,:],ws[i-4,:,:],ws[i-3,:,:],ws[i-2,:,:],ws[i-1,:,:],ws[i,:,:],0.25);
```


```
ac_mean = np.mean(ac,0); #Average accelerations 
lonM,latM = np.meshgrid(lon, lat);
fig = plt.figure(figsize=(10,8));
m = Basemap(resolution='l',projection='robin',lat_0=lat[0],lon_0=lon[0]);
m.shadedrelief(scale=0.5);
m.drawcoastlines(linewidth=1);
m.drawcountries(linewidth=1);
m.drawparallels(np.arange(-90,90,20));
m.drawmeridians(np.arange(0,357.5,20));
m.contourf(lonM,latM,np.abs(ac_mean),latlon=True,cmap='jet',alpha=0.6);
cbar = m.colorbar(location='bottom');
cbar.set_label(label='W');
cbar.set_label(label='Wind Acceleration in $m/s^2$', size=25);
plt.show();
```

**Recuerde:** En este curso no se tolerará el plagio. Sin excepción, en caso de presentarse esta situación, a los estudiantes involucrados se les iniciará proceso de investigación, y se actuará en conformidad con el Reglamento de Estudiantes de la Universidad del Norte. El plagio incluye: usar contenidos sin la debida referencia, de manera literal o con mínimos cambios que no alteren el espíritu del texto/código; adquirir con o sin intención, trabajos de terceros y presentarlos parcial o totalmente como propios; presentar trabajos en grupo donde alguno de los integrantes no trabajó o donde no hubo trabajo demostrable en equipo; entre otras situaciones definidas en el manual de fraude académico de la Universidad del Norte:

(https://guayacan.uninorte.edu.co/normatividad_interna/upload/File/Guia_Prevencion_Fraude%20estudiantes(5).pdf ).

eddb7d8692dc22b4e1e447bc8b52bc5f008c7b36
ipynb
Jupyter Notebook
High order differences/OPT_HW1.ipynb
QuantumGorilla/Optimization
ed7dc755cb1346d208f5f33fc4814e3931c9b44d
MIT
High order differences/OPT_HW1.ipynb
QuantumGorilla/Optimization
ed7dc755cb1346d208f5f33fc4814e3931c9b44d
MIT
High order differences/OPT_HW1.ipynb
QuantumGorilla/Optimization
ed7dc755cb1346d208f5f33fc4814e3931c9b44d
MIT
Qwen/Qwen-72B
1. YES
2. YES