In an optimization problem,if function zero(x ,y)
in the code given below is objective function with initial values of x,y
as 0,0
.Then, to solve the problem i need to compute the obj. function as well as its derivitive. So, when i am doing so,i am getting ZeroDivisionError: division by zero
.
[x,y] = [0,0]
def zero(x ,y):
return 3 + x/y + 2*xy + 1/x
Output is:
Traceback (most recent call last):
File "<ipython-input-5-4e3e5e87c5f1>", line 1, in <module>
runfile('C:/Users/HP/Documents/Python Scripts/Python Scripts_majrpjct/working/practice_cvxopt.py', wdir='C:/Users/HP/Documents/Python Scripts/Python Scripts_majrpjct/working')
File "C:\ProgramData\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/HP/Documents/Python Scripts/Python Scripts_majrpjct/working/practice_cvxopt.py", line 394, in <module>
print zero(x,y)
File "C:/Users/HP/Documents/Python Scripts/Python Scripts_majrpjct/working/practice_cvxopt.py", line 392, in zero
return 3 + x/y
ZeroDivisionError: division by zero
Can anyone suggest me a solution so as to get correct answer by ignoring ZeroDivisionError
values.