<jupyter_start><jupyter_text>1. Solve the given linear programming problemM ax Z = 5x1 − 2x2 + 3x3Subject to, 2x1 + 2x2 − x3 ≥ 23x1 − 4x2 ≤ 3x2 + 3x3 ≤ 5x1, x2, x3 ≥ 0<jupyter_code>import numpy as np
import scipy.optimize
from scipy.optimize import linprog
c=[-5,2,-3]
a=[[-2,-2,1],[3,-4,0],[0,1,3]]
b=[-2,3,5]
x1_bounds = (0,None)
x2_bounds = (0,None)
x3_bounds = (0,None)
res = linprog(c, a, b, bounds=(x1_bounds,x2_bounds,x3_bounds),options={"disp":True})
true_res=res.fun
print(true_res)<jupyter_output>-28.33333333333338<jupyter_text>2. Ackley function is defined asf(x, y) = −20e−0.2√0.5(x2+y2) − e0.5(cos(2πx)+cos(2πy)) + e + 20where e is the irrational number having value in between 2.71 and 2.72.Plot the function<jupyter_code>#!/usr/bin/env python
 
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import animation
 
#http://www.sfu.ca/~ssurjano/ackley.html
def ackley(x1,x2):
    a = 20
    b = 0.2
    c = 2*np.pi
     
    sum1 = x1**2 + x2**2
    sum2 = np.cos(c*x1) + np.cos(c*x2)
     
    term1 = - a * np.exp(-b * ((1/2.) * sum1**(0.5)))
    term2 = - np.exp((1/2.)*sum2)
 
    return term1 + term2 + a + np.exp(1)
 
plotN = 100
x1 = np.linspace(-20, 20, plotN)
x2 = np.linspace(-20, 20, plotN)
 
x1, x2 = np.meshgrid(x1,x2)
 
z = ackley(x1,x2)
 
fig = plt.figure()
 

ax = Axes3D(fig)
ax.plot_wireframe(x1,x2,z)
 
ax.zaxis.set_major_locator(plt.LinearLocator(10))
ax.zaxis.set_major_formatter(plt.FormatStrFormatter('%.01f'))
 
plt.show()
 

N = 10
x1_init = np.random.uniform(x1.min(),x1.max(),N)
x2_init = np.random.uniform(x2.min(),x2.max(),N)
z_init = ackley(x1_init,x2_init)
ax.plot(x1_init,x2_init,z_init,"o",c='red')
plt.show()
 
x1_old = np.copy(x1_init)
x2_old = np.copy(x2_init)
 
index = np.arange(N)
 

 
def animate(x1_new,x2_new,ims,ax2):
    z_new = ackley(x1_new,x2_new)
    im = ax2.plot(x1_new,x2_new,z_new,"o",c='green')
    ims.append(im)
    return ims
 
 
ims = []
fig2 = plt.figure()
ax2 = Axes3D(fig2)
ax2.plot_wireframe(x1,x2,z)
ax2.plot(x1_init,x2_init,z_init,"o",c='red')
 
for j in np.arange(100):
    for i in np.arange(N):
        rand_index = permutation(index)
        x1_proposal = x1_old[rand_index[0]] + 0.3*(x1_old[rand_index[1]]-x1_old[rand_index[2]])
        x2_proposal = x2_old[rand_index[0]] + 0.3*(x2_old[rand_index[1]]-x2_old[rand_index[2]])
 
        x1_log = np.copy(x1_old)
        x2_log = np.copy(x2_old)
 
        r1 = np.random.uniform(0,1,1)
        r2 = np.random.uniform(0,1,1)
 
        if r1 > 0.5:
            x1_old[i] = x1_proposal
        if r2 > 0.5:
            x2_old[i] = x2_proposal
 
        f_old = ackley(x1_log[i],x2_log[i])
        f_new = ackley(x1_old[i],x2_old[i])
 
        if f_new <= f_old:
            x1_new = np.copy(x1_old)
            x2_new = np.copy(x2_old)
        else:
            x1_new = np.copy(x1_log)
            x2_new = np.copy(x2_log)
 
    ims = animate(x1_new,x2_new,ims,ax2)
 
    x1_old = np.copy(x1_new)
    x2_old = np.copy(x2_new)
 
z_new = ackley(x1_new,x2_new)
ax.plot(x1_new,x2_new,z_new,"o",c='green')
plt.show()
 
anim = animation.ArtistAnimation(fig2,ims, interval=1, repeat_delay=1000)
plt.show()<jupyter_output><empty_output><jupyter_text>Given a set of points in eucledian plane, convex hull is defined as the smallest area convex polygon that encompasses all the points. Create n number of 2 − d points as n by 2 matrix and show its convex hull.<jupyter_code>>>> from scipy.spatial import ConvexHull
>>> points = np.random.rand(30, 2)   
>>> hull = ConvexHull(points)
>>> import matplotlib.pyplot as plt
>>> plt.plot(points[:,0], points[:,1], 'o')
>>> for simplex in hull.simplices:
...     plt.plot(points[simplex, 0], points[simplex, 1], 'k-')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1636556854410202, 'fraction_numerical': 0.06854410201912858, 'mean_word_length': 3.574726609963548, 'pattern_counts': {'":': 1, '<': 13, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '575419', 'license': 'MIT', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1703, 'n_words': 310, 'path': 'assignment_8 17IM3FP10.ipynb', 'repo_name': 'yashkundalia/information-system', 'size': '3764'}