0

I have two equations: one linear and one exponential, and I need to find where they intersect. They are of the form:

y1 = a * x
y2 = b * exp(c * x) + d

where the variables a, b, c and d are known.

I've tried looking online for solutions to find y1=y2, and y1-y2=0, but with no result. Are there any simple ways of solving these equations using Python?

import sympy
from sympy import Symbol

a = 2.06233087 
b = -0.41000778  
c = 0.44198402
d = 0.1251175917215428

x = Symbol('x', real=True)

result = sympy.solvers.solve(a*sympy.exp(b*x)+c-d*x, x)

Currently, I am trying to solve it with sympy solvers, but the equation above makes my computer 'crash'.

  • There are several equation solving tools for Python. They should all be able to minimize `abs(f1(x)-f2(x))`. – Tim Roberts Nov 02 '22 at 20:39
  • I think you could use SymPy. Can't remember how to do it off the top of my head though. You'll probably find it here: [Solvers](https://docs.sympy.org/latest/modules/solvers/solvers.html) – wjandrea Nov 02 '22 at 20:40
  • Steven, after you read the SymPy solvers documentation, please post an answer, separate from your question. https://stackoverflow.com/help/self-answer – J_H Nov 02 '22 at 20:45
  • So far, the Sympy solvers seem to be crashing in my case. Maybe my equation is too long or something. – Steven Bijl Nov 02 '22 at 21:33
  • I don't think that this equation can be solved in closed-form, though for any specific choice of `a` etc. you can solve it numerically. – John Coleman Nov 02 '22 at 22:48
  • Do you need numerical or analytical solution? – Yuri Ginsburg Nov 03 '22 at 00:07
  • @JohnColeman The solution of equation involves lambert's W-function. – Yuri Ginsburg Nov 03 '22 at 00:09
  • @YuriGinsburg Good to know, but if that is the case one would think that `SymPy` could handle it. – John Coleman Nov 03 '22 at 00:11
  • @JohnColeman Yes, sympy solves that as `-LambertW(-b*c*exp(c*d/a)/a)/c + d/a`. – Yuri Ginsburg Nov 03 '22 at 04:28
  • @StevenBijl For me sympy keeps running for ~15 minutes producing no results. I have built graphs of both functions and found that they have a single point of intersection with approximate coordinates `(x = -0.127, y = -0.262)`. – Yuri Ginsburg Nov 03 '22 at 04:50
  • @StevenBijl BTW you have different equations. From the text of your post `b * exp(c * x) + d - a*x) and in the code `a * exp(b * x) + c - d*x, x` – Yuri Ginsburg Nov 03 '22 at 06:55
  • Use `nsolve` instead of `solve`. – Yuri Ginsburg Nov 03 '22 at 06:58

0 Answers0