currently I try to calculate an exponential function of the following form: f(x) = aexp(-bx)+c
for context: this should be the reduction function of co2 emissions.
the conditions are following:
- f(x=0) = 700 Mt (current co2 emissions of Germany)
- f(x=30) = 0 Mt (no co2 emissions in 30 years)
- integral 0->30 f(x) = budget (remaining co2 budget - area under the curve)
I can solve this problem using matlab (solve-function)
But I want to do it in python but all the solvers I tried failed. When I use the solution of the matlab script as an initial guess everything works fine. But I don't want to do that. I want to use a python solver which works if I don't know a good initial guess.
Which one should I use? I tried fsolve from scipy and gekko so far.
Here's the code for my gekko attempt:
def solve(self, end_year, budget):
self.end_year = end_year
self.budget = budget
d_year = self.end_year - self.start_year
m = GEKKO()
a,b,c = [m.Var(1) for i in range(3)]
eq1 = a + c - self.co2_start
eq2 = a*m.exp(-b*d_year) + c
eq3 = a/b*(1-m.exp(-b*d_year))+c*d_year-self.budget
m.Equation([eq1==0, eq2==0, eq3==0])
m.solve(disp=False)
self.a, self.b, self.c = a.value, b.value, c.value
´´´