#Real Analysis

### 1. Sequences

For each of the patterns below, define a formula for $n$-th term $x_n$ of the sequence. Then, plot the first 20 terms of the sequences. Combine all three plots into a figure using the subplot command. Label everything.

a) 4, 8, 12, 16,...

b) 1, 6, 11, 16, 21, ...

c) 1/2, 2/3, 3/4, 4/5, ...

d) 1/2, -1/4, 1/8, -1/16, ...

e) 1, 1, 2, 3, 5, 8, ..



####Let a= first term, n=number of terms, d= difference between 2 consecutive terms, Then,
####a) nth term, Xn = a + (n-1)d = 4+(n-1)4 = 4+4n-4 = 4n
####b) nth term, Xn = a + (n-1)d = 1+(n-1)5 = 1+5n-5 = 5n-4
####c) nth term, Xn = $ \frac{n}{n+1}$
####d) nth term, Xn = $ \frac{(-1)^{n+1}}{2^n}$
####e) nth term, Xn = Xn-1 + Xn-2 (Fibonacci series)



```python
import matplotlib.pyplot as plt
%matplotlib inline
A1 = []    #Initializing an empty array for storing number of iterations value, n   
B1, B2, B3, B4, B5 = [], [], [], [], [] #Initializing empty arrays for storing sequence output
a1 = 4     #Initializing first term for P1.a
#Loop for getting the sequence for P1.a
for n in range(1, 21):
  a1 = 4*n
  A1.append(n)
  B1.append(a1)
print(B1,end=',\n')

a2 = 1     #Initializing first term for P1.b
#Loop for getting the sequence for P1.b
for n in range(1, 21):
  a2 = (5*n)-4
  B2.append(a2)
print(B2,end=',\n')

a3 = 1/2   #Initializing first term for P1.c
#Loop for getting the sequence for P1.c
for n in range(1, 21):
  a3 = n/(n+1)
  B3.append(a3)
print(B3, end=',\n')

a4 = 1/2  #Initializing first term for P1.d
#Loop for getting the sequence for P1.d
for n in range(1, 21):
  a4 = ((-1)**(n+1))/(2*n)
  B4.append(a4)
print(B4, end=',\n')

#Initializing sequence for P1.e
a = 0
b = 1
c = 0
B5.append(b)
#Loop for getting the sequence for P1.e
for n in range(19):
  c = a+b
  a = b
  b = c
  B5.append(c)
print(B5, end=',\n')

#Plotting all the sequences
fig,ax = plt.subplots(1,5, figsize = (30,5))
fig.suptitle('Plotting all the sequences', color='b')
ax[0].plot(A1,B1, 'r', label='4n'); ax[0].set_title('P1.a) 4, 8, 12, 16,...')
ax[1].plot(A1,B2, 'c', label='5n-4'); ax[1].set_title('P1.b) 1, 6, 11, 16, 21, ...')
ax[2].plot(A1,B3, 'g', label='n/(n+1)'); ax[2].set_title('P1.c) 1/2, 2/3, 3/4, 4/5, ...')
ax[3].plot(A1,B4, 'y', label='(-1)^(n+1)/2^n'); ax[3].set_title('P1.d) 1/2, -1/4, 1/8, -1/16, ...')
ax[4].plot(A1,B5, 'm', label='Fibonacci Series'); ax[4].set_title('P1.e) 1, 1, 2, 3, 5, 8, ..')
for i in range(5):
  ax[i].legend()
  ax[i].set_xlabel('Input-n')
  ax[i].set_ylabel('X_n')
```

### 2. Sequence Convergence

Show that the following sequences have the given limits using either an $\varepsilon-\delta$ argument, or an appropriate theorem from the lecture notes. 

a) $\lim \frac{3n+1}{2n+5} = \frac{3}{2}$

b) $\lim \frac{2n}{n+2} = 2$

c) $\lim\left(\frac{1}{n} - \frac{1}{n+1} \right) = 0$

d) $\lim \frac{n + 5}{n^{2}} = 0$

e) $\lim \left(\frac{1}{3n}\right)^{2} = 0$

P2.a. In this example, we have,
$f(x) = \frac {3n+1}{2n+5}$ and $Limit, L = \frac {3}{2}$. For any $\varepsilon > 0,  \left|f(x) - \frac{3}{2}\right| < \varepsilon$ proves the convergence.
\begin{aligned} \left| \frac {3n+1}{2n+5} - \frac {3}{2} \right| &= \left| \frac{(6n+2)-(6n+15)}{2(2n+5)}\right| < \varepsilon \\ &=) \left| \frac{-13}{4n+10}\right|<\varepsilon \\ &=) \left|\frac{-13}{4n}\right| < \varepsilon\\&=) \frac{13}{4n} < \varepsilon \\ &=) \frac{13}{4\varepsilon}<n\\&=)for\ n>N, we\ get, \ N=\left \lceil \frac{13}{4\varepsilon } \right \rceil \ satisfies\ the\ condition.
\end{aligned}
When we plot the difference of function and limit, $f(x)-L$ with $N\geq65$ and $\varepsilon=0.05$ it shows the convergence of $f(x)$.


```python
#P2.a
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

n = np.linspace(65 , 100, 200)
#Plotting the sequence for N>=65 and ep=0.05
plt.plot(n, 3/2-(3*n+1)/(2*n+5), 'r', label='x_n=Convergence')
plt.title('P2.a')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

P2.b. In this example, we have,
$function, f(x) = \frac {2n}{n+2}$ and $Limit, L = 2$. For any $\varepsilon > 0 ,  \left|f(x) - 2\right| < \varepsilon$ proves the convergence.
\begin{aligned} \left| \frac {2n}{n+2} - 2 \right| &= \left| \frac{2n-2(n+2)}{n+2}\right| = \left| \frac{4}{n+2}\right|< \varepsilon \\&=)\frac {4}{n+2} < \varepsilon \\ &=) \frac {n+2}{4} > \frac{1}{\varepsilon}  \\ &=) n > \frac{4}{\varepsilon}-2\\& =)for\ n>N, we\ get, N=\left \lceil \frac{4}{\varepsilon}-2\right \rceil\ satisfies\ the\ condition.
\end{aligned}
When we plot the difference of function and limit, $f(x)-L$ with $N\geq78$ and $\varepsilon=0.05$ it shows the convergence of $f(x)$.


```python
#P2.b
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

n = np.linspace(78 , 100, 200)
#Plotting the sequence for N>=78 and ep=0.05
plt.plot(n, 2-(2*n)/(n+2), 'b', label='x_n=Convergence')
plt.title('P2.b')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

P2.c. In this example, we have,
$function, f(x) = \frac {1}{n}-\frac {1}{n+1}$ and $Limit, L = 0$. For any $\varepsilon > 0 ,  \left|f(x) - 0\right| < \varepsilon$ proves the convergence.
\begin{aligned} \left| \frac {1}{n}-\frac {1}{n+1} \right| &< \left| \frac{1}{n}\right|< \varepsilon \\&=)\frac {1}{n} < \varepsilon \\ &=)\frac {1}{\varepsilon} < n, \ for\ n>N, we\ get, N=\left \lceil \frac{1}{\varepsilon}\right \rceil\ satisfies\ the\ condition.
\end{aligned}
When we plot the difference of function and limit, $f(x)-L$ with $N\geq20$ and $\varepsilon=0.05$ it shows the convergence of $f(x)$.


```python
#P2.c
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

n = np.linspace(20 , 100, 200)
#Plotting the sequence for N>=20 and ep=0.05
plt.plot(n, 1/n-1/(n+1), 'g', label='x_n=Convergence')
plt.title('P2.c')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

P2.d. In this example, we have,
$function, f(x) = \frac {n+5}{n^2}$ and $Limit, L = 0$. For any $\varepsilon > 0 ,  \left|f(x) - 0\right| < \varepsilon$ proves the convergence.
\begin{aligned} &\left| \frac {n+5}{n^2}\right| < \varepsilon \\&\left| \frac {n+5}{n^2}\right| >\left| \frac{n}{n^2}\right|=)\left| \frac{n}{n^2}\right|< \varepsilon \\&=) \frac{1}{n}< \varepsilon\\&=) \frac{1}{\varepsilon} < n, \ as\ n>N, we\ get, N=\left \lceil \frac {1}{\varepsilon}\right \rceil\ satisfies\ the\ condition.
\end{aligned}
When we plot the difference of function and limit, $f(x)-L$ with $N\geq20$ and $\varepsilon=0.05$ it shows the convergence of $f(x)$.


```python
#P2.d
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

n = np.linspace(20 , 100, 200)
#Plotting the sequence for N>=20 and ep=0.05
plt.plot(n, (n+5)/(n**2), 'm', label='x_n=Convergence')
plt.title('P2.d')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

P2.e. In this example, we have,
$function, f(x) = (\frac {1}{3n})^2$ and $Limit, L = 0$. For any $\varepsilon > 0 ,  \left|f(x) - 0\right| < \varepsilon$ proves the convergence.
\begin{aligned} \left| (\frac {1}{3n})^2-0\right| &< \varepsilon \\&\left| \frac {1}{9n^2}\right| < \varepsilon \\&=) \frac{1}{9n^2}< \varepsilon\\&=) \frac{1}{9\varepsilon}< n^2 \\ &=)\frac {1}{3\sqrt\varepsilon} < n, \ for\ n>N, we\ get, N=\left \lceil \frac {1}{3\sqrt\varepsilon}\right \rceil\ satisfies\ the\ condition.
\end{aligned}
When we plot the difference of function and limit, $f(x)-L$ with $N\geq1.5$ and $\varepsilon=0.05$ it shows the convergence of $f(x)$.


```python
#P2.e
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

n = np.linspace(1.5 , 100, 200)
#Plotting the sequence for N>=1.5 and ep=0.05
plt.plot(n, ((1/(3*n))**2), 'y', label='x_n=Convergence')
plt.title('P2.e')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

### 3. Proving non-convergence

Show that the sequence $(x_n)$ where $x_n = (-1)^n$ does not converge to any number $c$. Use the definition of a limit for sequences. Given $\varepsilon > 0$, you have to show that there does not exist an $m$ such that for all $n>m$ such that $c-\varepsilon < x_n < c+\varepsilon$. 

In this example, lets assume,
$f(x) = x_n = (-1)^n$ converges to any number $c$. For any $$\varepsilon > 0 ,  \left|f(x) - c\right| < \varepsilon$$ proves the convergence.
$$\left| (-1)^n-c\right| < \varepsilon$$Let, $\varepsilon=\frac{1}{2}$.By definition of convergence, we can have N such that for any n>N, $$\left| (-1)^n-c\right| < \frac{1}{2}$$It means that the maximum distance between any two points $(−1)^n$ and $(−1)^m$, for m,n>N, can be $2*\frac{1}{2}=1$, as they are both $\frac{1}{2}$ away from c. 
But this cannot be true as the distance between any $(−1)^n$ and $(−1)^{n+1}$ is 2 for n>N. Therefore the sequence does not converge for $\varepsilon=\frac{1}{2}$ and hence given sequence is not convergent (seen in the plot as well).


```python
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

n = np.linspace(1 , 20, 20)
#Plotting the sequence
plt.plot(n, (-1)**n, 'b', label='x_n=Non-Convergence')
plt.title('P3')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

### 4. Sequences via recurrence relations

Let $x_0 = 1$ and $x_{i+1} = - a x_i$ where $0 < a < 1$.

a) Plot the first 20 points in $(x_n)$ when $a=\frac{1}{2}$. 

b) Show that $(x_n)$ converges to 0. 


```python
import matplotlib.pyplot as plt
%matplotlib inline

x = 1   #Initializing the sequence
a = 1/2 #Initializing the constant
A , B= [],[] #Intializing empty arrays for storing number of iterations and sequence outputs
#Loop for getting the sequence
for n in range(20):
  x = -a*x
  A.append(n)
  B.append(x)
  print(n+1,")", x, end=',')
#Plotting the sequence
plt.plot(A, B, 'r', label='-ax, a=1/2')
plt.title('P4. Sequences via recurrence relations')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

For the given conditions: $x_0 = 1$ and $x_{i+1} = - a x_i$ where $0 < a < 1$, when we select $n=20, a=\frac{1}{2}$ and plot the sequence, it is clearly observed that the sequence $(x_n)$ converges to 0.

 ### 5. Sequences via recurrence relations - 2

Let $x_0 = 1$ and $x_{i+1} = - a x_i + \frac{1}{5}$ where $0 < a < 1$.

a) Plot the first 20 points in $(x_n)$ when $a=\frac{1}{3}$. 

b) Show that $(x_n)$ converges to 0. 


```python
import matplotlib.pyplot as plt
%matplotlib inline

x = 1   #Initializing the sequence
a = 1/3 #Initializing the constant
A , B= [],[] #Intializing empty arrays for storing number of iterations and sequence outputs
#Loop for getting the sequence
for n in range(20):
  x = -a*x+(1/5)
  A.append(n)
  B.append(x)
  print(n+1,")", x, end=',')
#Plotting the sequence
plt.plot(A, B, 'm', label='-ax+(1/5),a=1/3')
plt.title('P5. Sequences via recurrence relations-2')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

For the given conditions: $x_0 = 1$ and $x_{i+1} = - a x_i+ \frac{1}{5}$ where $0 < a < 1$, when we select $n=20$ and $a=\frac{1}{3}$ and plot the sequence, it is clearly observed that the sequence $(x_n)$ converges to a constant value= $ 0.15$.

 ### 6. Sequences via recurrence relations - 3

Let $x_0 = 1$ and $x_{i+1} = - a x_i$ where $0 < a \leq 1$.

a) Plot the first 20 points in $(x_n)$ when $a=1$. 

b) What happens with the convergance of the given sequences $(x_n)$?


```python
import matplotlib.pyplot as plt
%matplotlib inline

x = 1 #Initializing the sequence
a = 1 #Initializing the constant
A , B= [],[] #Intializing empty arrays for storing number of iterations and sequence outputs
#Loop for getting the sequence
for n in range(20):
  x = -a*x
  A.append(n)
  B.append(x)
  print(n+1,")",x, end=',')
#Plotting the sequence
plt.plot(A, B, 'g', label='-ax, a=1')
plt.title('P6. Sequences via recurrence relations-3')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

For the given conditions: $x_0 = 1$ and $x_{i+1} = - a x_i$ where $0 < a \leq 1$, when we select $n=20$ and $a=1$ and plot the sequence, it is clearly observed that the sequence $(x_n)$ is not convergent and becomes cyclic and ranges between $-1\:to\: 1$.

 ### 7. Sequences via recurrence relations - 7

Let $x_0 = 1$ and $x_{i+1} = a x_i$ where $a \geq 1$.

a) Plot the first 20 points in $(x_n)$ when $a= \frac{3}{2}$. 

b) What happens with the convergance of the given sequences $(x_n)$?


```python
import matplotlib.pyplot as plt
%matplotlib inline

x = 1 #Initializing the sequence
a = 3/2 #Initializing the constant
A , B= [],[] #Intializing empty arrays for storing number of iterations and sequence outputs
#Loop for getting the sequence
for n in range(20):
  x = a*x
  A.append(n)
  B.append(x)
  print(n+1,')',x, end=',')
#Plotting the sequence
plt.plot(A, B, 'y', label='ax, a=3/2')
plt.title('P7. Sequences via recurrence relations-7')
plt.xlabel('Input-n')
plt.ylabel('x_n')
plt.legend()
```

For the given conditions: $x_0 = 1$ and $x_{i+1} = a x_i$ where $a \geq 1$, when we select $n=20$ and $a=\frac{3}{2}$ and plot the sequence, it is clearly observed that the sequence $(x_n)$ is not convergent as it moves towards infinity.

### 8. Definition of Derivative

Use the definition of the derivative to find the derivatives of the following functions.

a) $f(x) = x^3$, for any $x$

b) $g(x) = 1/x$, for $x \neq 0$

c) $h(x) = \sqrt{x}$, for $x > 0$

d) $k(x) = x^{-1/2}$ for $x > 0$.

$$a) f(x)=x^3$$
$$Using\:Power\:Rule,\frac{dx^n}{dx}=nx^{n-1}, for\: n=3$$
$$df(x)/dx= 3x2$$
$$----------------------------------------------$$
$$b) g(x)=1/x\:or\: x^{-1}$$
$$Using\:Power\:Rule,\frac{dx^n}{dx}=nx^{n-1}, for\: n=-1$$
$$dg(x)/dx= -1x^{-2}\:or\: \frac{-1}{x^2}$$
$$----------------------------------------------$$
$$c) h(x)=\sqrt{x}\: or\: x^{1/2}$$
$$Using\:Power\:Rule,\frac{dx^n}{dx}=nx^{n-1}, for\: n=1/2$$
$$dh(x)/dx= (1/2)*x^{-1/2}\:  or\:  \frac{1}{2\sqrt{x}}$$
$$----------------------------------------------$$
$$d) k(x)=x^{-1/2}$$
$$Using\:Power\:Rule,\frac{dx^n}{dx}=nx^{n-1}, for\: n=-1/2$$
$$dk(x)/dx= (-1/2)*x^{-3/2}\: or\:  \frac{-1}{2x\sqrt{x}}$$
$$----------------------------------------------$$

### 9. The Chain Rule

Use the chain rule to find these deriviatives. Verify your results with `sympy`.

a) $f(x) = \frac{1}{1+x^2}$

b) $h(x) = (\sin x^k)^m$ for $m,k \in \mathbb{N}$

$a)f(x)= \frac{1}{1+x^2}$
$$Let,u = x^2, f = \frac{1}{1+u} or (1+u)^{-1}$$
$$Using\:Power\:Rule,du/dx=2x\:,df/du=-1*(1+u)^{-2}\:or\:\frac{-1}{(1+u)^2}$$
$$Using\:Chain\:Rule,\frac{df}{dx}=\frac{df}{du}\frac{du}{dx}=\frac{-2x}{(1+u)^2}=\frac{-2x}{(1+x^2)^2}$$ 
$$----------------------------------------------$$
$b)h(x)= (\sin x^k)^m$
$$Let,u = x^k, v = \sin u, f = v^m$$
$$Using\:Power\:Rule,du/dx=kx^{k-1}\:,dv/du=cos u\:,df/dv=mv^{m-1}$$
$$Using\:Chain\:Rule,\frac{df}{dx}=\frac{df}{dv}\frac{dv}{du}\frac{du}{dx}=mv^{m-1}*cos u*kx^{k-1}$$
$$=mkx^{k-1}\ (sin x^k)^{m-1}cos x^k$$ 
$$----------------------------------------------$$



```python
#Code for P9.a
import sympy as sm
#Initializing the symbol
x = sm.symbols("x")
sm.diff(1/(1+x**2),x) #Performing the differentiation
```




$\displaystyle - \frac{2 x}{\left(x^{2} + 1\right)^{2}}$




```python
#Code for P9.b
import sympy as sm
#Initializing the symbols
x = sm.symbols("x")
k = sm.symbols("k")
m = sm.symbols("m")

#Substituting the symbols with some variables
u = x**k
v = sm.sin(x)
f = x**m
vou = v.subs(x,u)
fov = f.subs(x,vou)

dfov = sm.diff(fov,x) #Performing the differentiation

dfov
```




$\displaystyle \frac{k m x^{k} \sin^{m}{\left(x^{k} \right)} \cos{\left(x^{k} \right)}}{x \sin{\left(x^{k} \right)}}$



c13e17c5d6392e2ab4b8f46630cc0cd8c2f30311
ipynb
Jupyter Notebook
Real Analysis/Real Analysis.ipynb
joy6543/Mathematics-and-Analytical-Methods
eea45c7ffd98c308254142903ef661c792fa3503
MIT
Real Analysis/Real Analysis.ipynb
joy6543/Mathematics-and-Analytical-Methods
eea45c7ffd98c308254142903ef661c792fa3503
MIT
Real Analysis/Real Analysis.ipynb
joy6543/Mathematics-and-Analytical-Methods
eea45c7ffd98c308254142903ef661c792fa3503
MIT
Qwen/Qwen-72B
1. YES
2. YES