# Computational and Numerical Methods
## Group 16
### Assignment 1
#### Vidhin Parmar   201601003
#### Parth Shah      201601086

<form action="javascript:code_toggle()"><input type="submit" id="toggleButton" value="Show Code"></form>

```python
import numpy as np
from matplotlib import pyplot as plt
import math
import pandas as pd
import warnings
import sympy
warnings.filterwarnings('ignore')
```

##  Q1.a


```python
i = np.arange(0.001, 1, 0.001)
k = 1
y = -k*((i*(np.log2(i))+((1-i)*np.log2(1-i))))
plt.plot(i, y, label ="<I> vs p")
plt.grid(True)
plt.legend(loc = 'best')
plt.show()
```

We can see that the graph peaks when the value of P is 0.5

##  Q1.b

$I =-k(plog_{2}p+(1-p)(log_{2}(1-p)))$

$p = 0.5 + \epsilon$

$\therefore $ $I =-k((0.5+\epsilon)log_{2}(0.5+\epsilon)+(0.5-\epsilon)(log_{2}(0.5-\epsilon)))$

$\therefore I = -k((0.5 + \epsilon)(\frac{(\ln(1+ 2\epsilon)}{\ln{2}})+(0.5 - \epsilon)(\frac{(\ln(1- 2\epsilon)}{\ln{2}}))$

$\therefore I = -k((0.5 + \epsilon)(\frac{2\epsilon}{\ln2})+(0.5 - \epsilon)(\frac{-2\epsilon}{\ln2})$

$\therefore I = \frac{-4k(\epsilon)^2}{\ln(2)} +k$

$\therefore I = a -b \epsilon^2$ $ where$ $ a = k$ $ and $ $b = \frac{4k}{\ln(2)}$

##  Q1.c


```python
plt.plot(i, -k*((i*(np.log2(i))+((1-i)*np.log2(1-i)))), label ="<I> vs p")
plt.plot(i, k-4*k*(((0.5-i)**2)/(np.log(2))), label ="Approx <I> vs p")
plt.grid(True)
plt.legend(loc = 'best')
plt.show()
```

# Q2



# Question 3


```python
M = 2*(10**30)
c = (10**4)
P = (10**(-21))
Y = 7/5

```


```python
B = 2
R = np.arange(2,0.7254,-0.0001)
vals1 = []
vals2 = []
x1 = []
x2 = []
for r in R:
  coeff = [r**4, 0, -B*(r**4), -4*(r**2), 3]
  roots = np.roots(coeff)
#   print(r)
  [y1, y2] = np.real(roots[np.imag(roots)==0])
  x1.append((r**-2)*(y1**-1))
  x2.append((r**-2)*(y2**-1))
  vals1.append(y1)
  vals2.append(y2)

vals1 = np.array(vals1)
vals2 = np.array(vals2)
x1 = np.array(x1)
x2 = np.array(x2)
plt.plot(R, vals1)
plt.grid(True)
plt.plot(R, vals2)
plt.plot(R, (x1*((3*x1) - 2))**0.5)
plt.plot(R, (x2*((3*x2) - 2))**0.5)
plt.show()
```

#  Question 4


```python
f = lambda h: (0.75)/(1-(h**3))
h = np.arange(0,1,0.0001)
plt.plot(h,f(h))


h = np.arange(1,2,0.0001)
plt.plot(h,f(h))
plt.grid(True)
plt.yscale('symlog')
plt.show()
```


```python
X = np.arange(0,1,0.0001)
vals1 = []
for x in X:
  coeff = [1, 0, 0, -4, 3*x]
  roots = np.roots(coeff)
  [x1, x2] = np.real(roots[np.imag(roots)==0])
  vals1.append(x2)
  
plt.plot(X, vals1)
  
X = np.arange(1.001,2,0.0001)
val = []
arr = []
for x in X:
  coeff = [1, 0, 0, -4, 3*x-3]
  roots = np.roots(coeff)
  [x1, x2]  = np.real(roots[np.imag(roots)==0])
  val.append(x1)
 
plt.plot(X, val)
plt.grid(True)
plt.show()
```

# Question 5: The Lienard System



The closed ellipse is for Epsilon = 0. The others are for Epsilon = 1. (0.95,0) gives the spiral and (1.05, 0) gives the open curve.


```python

```

45aae96a61a5e255ef5cef1ac1087ebd105df12c
ipynb
Jupyter Notebook
src/Assignment_1.ipynb
Vidhin05/CNM
4d3757850cb96dd297a26487a3a73ed4a8560bb0
BSD-3-Clause
2018-12-04T22:02:51.000Z
2018-12-04T22:02:58.000Z
src/Assignment_1.ipynb
Vidhin05/Computational-and-Numerical-Methods
4d3757850cb96dd297a26487a3a73ed4a8560bb0
BSD-3-Clause
2018-10-29T11:42:42.000Z
2018-11-12T10:38:39.000Z
src/Assignment_1.ipynb
Vidhin05/CNM
4d3757850cb96dd297a26487a3a73ed4a8560bb0
BSD-3-Clause
2021-06-04T05:20:21.000Z
2021-06-04T05:20:21.000Z
Qwen/Qwen-72B
1. YES
2. YES