[英]Python intersection point for two functions
我正在嘗試找到兩個功能之間的交叉點。 P_g現在是一個常數,但我希望它是靈活的,以便可以將其更改為正弦或線性增加。
import numpy as np
import matplotlib.pyplot as plt
d = 100. # price at 0 catch sales local market
b1 = 0.05 # slope of price curve for species1
p = 50. # # price for species1 global
P_g = p # constant for price species1 global
P_l = d * np.exp(-b1*x) # price species1 local market
在我看來,最合適的解決方案是:
P_g = ImplicitRegion[{y == p}, {x, y}]
P_l = ImplicitRegion[{y == d* np.exp(-b1*x)}, {x, y}]
solve[{k /[Element] P_g, k /[Element] P_l}, {k}]
這給了我:SyntaxError:無效的語法
您可以通過scipy.optimize.fsolve(lambda x : d * np.exp(-b1*x) -P_g,0)
找到它
或解析地求解: x=-np.log(P_g/d)/b1.
在這兩種情況下,您都可以找到: x=13.862943611198906
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.