Thursday, 15 March 2012

numpy - Can't differentiate with respect to the variable in python -



numpy - Can't differentiate with respect to the variable in python -

import sympy sympy import * sympy import diff import numpy np alpha = symbol('alpha') beta = symbol('beta') delta = symbol('delta') css = symbol('css') cssn = symbol('cssn') kssn = symbol('kssn') kssn = ((((1/beta)+ (alpha*delta) - 1)/(1-alpha)) + delta)**alpha css = (((1/beta)+ (alpha*delta) - 1)/(1-alpha))*kssn cssn = (((1/beta)+ (alpha*delta) - 1)/(1-alpha))*kssn eps = 0.0001*np.abs(css) eps1 = 0.0001*np.abs(kssn) res = (1/css) - (beta/cssn)*(1 - delta + (1 - alpha)*(kssn**(-alpha))) res1 = (1/css+eps) - (beta/cssn)*(1 - delta + (1 - alpha)*(kssn**(-alpha))) res2 = (1/css) - (beta/cssn+eps)*(1 - delta + (1 - alpha)*(kssn**(-alpha))) res3 = (1/css) - (beta/cssn)*(1 - delta + (1 - alpha)*((kssn+eps1)**(-alpha))) x1 = diff(res1, css) x2 = diff(res2, cssn) x3 = diff(res3, kssn) b1 = (x1 - x)/eps b2 = (x2 - x1)/eps b3 = (x3 - x2)/eps1

error message:

class="lang-none prettyprint-override"> file "hw5.py", line 33, in <module> x1 = diff(res1, css) file "/users/obrienstp/anaconda/lib/python2.7/site-packages/sympy/core/function.py", line 1641, in diff homecoming derivative(f, *symbols, **kwargs) file "/users/obrienstp/anaconda/lib/python2.7/site-packages/sympy/core/function.py", line 1029, in __new__ can\'t differentiate wrt variable: %s, %s''' % (v, count))) valueerror: can't differentiate wrt variable: 0.0103498953698543, 1

will help me prepare this? literally punch hole in wall. new programming , have spent 3 days working on this. why saying error , how prepare it?

when situation this, utilize interpreter give feedback:

>>> # variables in res1? ... >>> res1.free_symbols set([delta, alpha, beta]) >>> # css? ... >>> css (delta + (alpha*delta - 1 + 1/beta)/(-alpha + 1))**alpha*(alpha*delta - 1 + 1/be ta)/(-alpha + 1)

as noted, can't differentiate respect expression. can differentiate wrt symbol (or function).

python-2.7 numpy sympy

No comments:

Post a Comment