Created
March 8, 2019 16:45
-
-
Save ahmed2m/43e8df798187ec49216be0d337e9d309 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# This line configures matplotlib to show figures embedded in the notebook, \n", | |
"# instead of poping up a new window. More about that later. \n", | |
"\n", | |
"%matplotlib widget\n", | |
"import math\n", | |
"import matplotlib.pyplot as plt\n", | |
"import numpy as np\n", | |
"from mpl_toolkits import mplot3d\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The minimum point is (-0.006012024048096087, 1.5811623246492985)\n" | |
] | |
} | |
], | |
"source": [ | |
"def f(x, y):\n", | |
" return -1*(3*( (1-x)**2 ) * np.exp( -(x**2)-(y+1)**2 ) - 10*(x/5 - (x**3) -(y**5)) * np.exp(-(x**2) - (y**2)) - (1/3)*np.exp(-((x+1)**2) -(y**2)))\n", | |
"\n", | |
"\n", | |
"min = 999\n", | |
"test=(0,0)\n", | |
"\n", | |
"for x in np.linspace(-3,3,500):\n", | |
" for y in np.linspace(-3,3,500):\n", | |
" test1=f(x,y)\n", | |
" \n", | |
" if(test1<min):\n", | |
" min = test1\n", | |
" test=(x,y)\n", | |
"\n", | |
"print(\"The minimum point is \",test)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Bruteforcing on the surface using evenly spaced decimals in R 200x200: (2.9899497487437188, 4.994974874371859)\n", | |
"Brute force with fixed step of 0.01: (3.0, 5.0)\n" | |
] | |
} | |
], | |
"source": [ | |
"def f(x, y):\n", | |
" return 4*x + 5*y\n", | |
"\n", | |
"\n", | |
"max = -999\n", | |
"test=(0,0)\n", | |
"count=0\n", | |
"for x in np.linspace(0,7,200):\n", | |
" for y in np.linspace(0,7,200):\n", | |
" if x+y<=8 and 2*x+y<=14 and x+3*y<=18 and (x!=0 and y!=0):\n", | |
" comp=f(x,y)\n", | |
"# count+=1\n", | |
"# print(\"the x:\",x,\" the y:\",y,\" the fun:\",test1)\n", | |
" if(comp>max):\n", | |
" max = comp\n", | |
" test=(x,y)\n", | |
"\n", | |
"print(\"Bruteforcing on the surface using evenly spaced decimals in R 200x200: \", test)\n", | |
"\n", | |
"max = -999\n", | |
"test=(0,0)\n", | |
"# print(np.arange(0,7,0.01).size)\n", | |
"for x in np.arange(0,7,0.01):\n", | |
" for y in np.arange(0,7,0.01):\n", | |
" if x+y<=8 and 2*x+y<=14 and x+3*y<=18 and (x!=0 and y!=0):\n", | |
" comp=f(x,y)\n", | |
"# print(\"the x:\",x,\" the y:\",y,\" the fun:\",test1)\n", | |
" if(comp>max):\n", | |
" max = comp\n", | |
" test=(x,y)\n", | |
"\n", | |
"print(\"Brute force with fixed step of 0.01: \" ,test)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python [conda env:selected_venv]", | |
"language": "python", | |
"name": "conda-env-selected_venv-py" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment