How to use SymPy to find the point of intersection of two functions?

坚强是说给别人听的谎言 提交于 2019-12-11 06:38:54

问题


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?

来源:https://stackoverflow.com/questions/54352757/how-to-use-sympy-to-find-the-point-of-intersection-of-two-functions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!