-1

I have an equation in 4 variables x, v, eta(e), beta(b). I want to substitute x and v with various values and create an equation by multiplying all the obtained terms. Image of Code in sympy

Using SYMPY, How to solve the obtained equation in 2 variables(e and b) taking a log and differentiating with respect to e and then b? I am taking 'ln' so that the multiplicative terms get simplified to additive terms and hence exponential terms get eliminated. But, it is not happening. It just writes the word log in front but doesn't expand using the property ln(mn) = ln(m) + ln(n)

Following is the output in console:

Output in console when I run code shown in previous image

  • Please provide your code in a format that can be copy-pasted. In the meantime, try calling `sp.expand_log` with the option `force=True` – Stelios Feb 06 '17 at 08:31
  • @Stelios, I am still not able to eliminate the exponential terms from after force = true in expand_log PFB code: from sympy.solvers.pde import pdsolve from sympy import Function , diff , Eq from sympy.abc import x,y,z,v from sympy import * # from sympy import IndexedBase , Idx, symbols , oo import sympy as sp # import numpy # from mpmath import * # from sympy.tensor.array import Array e, b, a= sp.symbols('e b a') Continued..... – Amrit Bhatia Feb 06 '17 at 08:41
  • x = sp.IndexedBase('x') v = sp.IndexedBase('v') i , j = sp.symbols('i j' , cls=Idx) def f(x, v, e, b): y = (((x + v)/e)**(b-1))*(sp.exp((v/e)**b - ((x+v)/e)**b)) return y # # n= 0 for i in range(0,6): x = x[i].subs(x[i], (2,3,4,5,4,1)) v = v[i].subs(v[i],(1,2,3,4,5,6)) o = sp.ln(f(x[i],v[i],e,b)) n += o print(n) def m(e,b): m= sp.expand_log(sp.ln(n)) return m print(m(e,b)) eqs = (sp.diff(n,e) , sp.diff(n,b)) print(eqs) print(sp.solve(eqs)) – Amrit Bhatia Feb 06 '17 at 08:41
  • I made some changes in code: Please see below n= 1 for i in range(0,6): x = x[i].subs(x[i], (2,3,4,5,4,1)) v = v[i].subs(v[i],(1,2,3,4,5,6)) n *= f(x[i],v[i],e,b) print(n) def m(e,b): m= sp.expand_log(sp.ln(n), force= true) sp.simplify(m) return m print(m(e,b)) eqs = (sp.diff(m(e,b),e) , sp.diff(m(e,b),b)) print(eqs) print(sp.solve(eqs)) Now the exponential terms are eliminated, thanks @Stelios But error 'could not solve equations' in console remains the same. – Amrit Bhatia Feb 06 '17 at 08:55
  • Please paste your code here. No one is going to attempt to retype your code from an image. – asmeurer Feb 08 '17 at 17:52

1 Answers1

0

You may need to set your various symbols as positive, like x = symbols('x', positive=True). Identities like log(x*y) == log(x) + log(y) and log(exp(x)) == x are not true in general, but they are true when the variables are positive.

asmeurer
  • 86,894
  • 26
  • 169
  • 240