2

I am trying to use the SymPy library to find the point of intersection(s) between two functions:

f(x) = e ^ (x / 2) and g(x) = 3 - 3 * x

I tried:

import sympy as syp

x = syp.symbols('x')

f_x = syp.E ** (x / 2)
g_x = 3 - 3 * x

print(syp.nsolve(f_x, g_x, x))

syp.nsolve(f_x, g_x, x) spits out a TypeError. Replacing that line with syp.solve([f_x, g_x], x) results in an empty list []. This is wrong because f(x) and g(x) intersect at exactly one point.

How do I get the x and y values of the point of intersection(s) between any f(x) and g(x) using SymPy?

Primusa
  • 13,136
  • 3
  • 33
  • 53
parrot15
  • 309
  • 3
  • 13
  • Maybe https://stackoverflow.com/questions/28766692/intersection-of-two-graphs-in-python-find-the-x-value ? – JohanC Oct 29 '19 at 18:15

1 Answers1

-1
import sympy as syp

x = syp.symbols('x')

f_x = syp.E ** (x / 2)
g_x = 3 - 3 * x

print(syp.solve(f_x - g_x, x))

The output of the above code is:

[-2*LambertW(exp(1/2)/6) + 1]
Joe Ferndz
  • 8,417
  • 2
  • 13
  • 33
Diego Quirós
  • 898
  • 1
  • 14
  • 28