This repository has been archived on 2025-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
Files_for_MM/stabilityO.py
2025-01-26 21:49:59 +08:00

62 lines
1.7 KiB
Python

import numpy as np
import json
import matplotlib.pyplot as plt
colorList = json.load(open('color/config.json','r'))["color"]
psgRange=np.arange(1e6,5e6,1e5,dtype=np.float64)
prediction = 2433827
taxShift=0.03
torShift=1-0.054
curTaxationRate=1.0
def tax(x):
temp1 = np.log(prediction/(torShift**(curTaxationRate/taxShift)))
temp2 = np.log(torShift)
return taxShift*(np.log(x)-temp1)/temp2
def predictTotalPassengers(taxationRate):
return (prediction/(torShift**(curTaxationRate/taxShift)))*(torShift**(taxationRate/taxShift))
RNGk = 37.648854
RNGb = 59397421.185785
def f1(x):
temp3=(curTaxationRate*(RNGk*(predictTotalPassengers(curTaxationRate))+RNGb))
return 5*((tax(x))*(RNGk*x+RNGb) / temp3 -1)+1
C2=1
Cb2=1e8
iceberg = -0.2
def f2(x):
return 1 - C2*x/Cb2 + iceberg
C3=1
Cb3=4e8
def f3(x):
return 1 - C3*x/Cb3
influenceFactor = np.array([0.21061,0.54848,0.24091],dtype=np.float64)
def f(x):
return f1(x)*influenceFactor[0] + f2(x)*influenceFactor[1] + f3(x)*influenceFactor[2]
from scipy.optimize import minimize_scalar
result = minimize_scalar(lambda x: -f(x),bounds=(np.min(psgRange),np.max(psgRange)),method='bounded')
plt.plot(psgRange,f(psgRange),color=colorList[0],label='case 0')
cur_x = iceberg
cur_y = result.x
tag = 1e-10
alt_x = iceberg
alt_y = minimize_scalar(lambda x: -f(x),bounds=(np.min(psgRange),np.max(psgRange)),method='bounded').x
while abs(alt_y-cur_y)<10:
iceberg += tag
alt_x = iceberg
alt_y = minimize_scalar(lambda x: -f(x),bounds=(np.min(psgRange),np.max(psgRange)),method='bounded').x
tag *= 2
plt.plot(psgRange,f(psgRange),color=colorList[1],label='case 1')
plt.legend()
plt.show()
print(cur_x,cur_y,alt_x,alt_y)
print((alt_y-cur_y)/(alt_x-cur_x))