I've been trying to solve a system of equations in Python and checking the solution in Excel.
The python code is as follows:
from sympy import Symbol, solvers
a = Symbol('a', real=True)
b = Symbol('b', real=True)
c = Symbol('c', real=True)
d = Symbol('d', real=True)
Dy = Symbol('Dy', real=True)
Du = Symbol('Du', real=True)
Ay = Symbol('Ay', real=True)
Au = Symbol('Au', real=True)
f1 = -a*(Dy)**3+b*(Dy)**2+c*Dy+d-Ay
f2 = -a*(Du)**3+b*(Du)**2+c*Du+d-Au
f3 = -3*a*(Dy)**2+2*b*Dy+c-Ay/Dy
f4 = -3*a*(Du)**2+2*b*Du+c
print(solvers.solve((f1, f2, f3, f4), (a, b, c, d)))
Then I used the equations for (a,b,c,d)
in Excel and plotted the curve.
I could see that the curve is not what I expected (at x=Dy
and x=Du
).
Therefore, I asked Python to output the values of (a,b,c,d)
for known values of (Dy,Ay,Du,Au)
.
The values I obtained from Python are very different than the ones from Excel:
a= (2*Au*Dy - Ay*Du - Ay*Dy)/(Dy*(Du**3 - 3*Du**2*Dy + 3*Du*Dy**2 - Dy**3))
c= Du*(-6*Au*Dy**2 + Ay*Du**2 + Ay*Du*Dy + 4*Ay*Dy**2)/(Dy*(Du**3 - 3*Du**2*Dy + 3*Du*Dy**2 - Dy**3))
b= (3*Au*Du*Dy + 3*Au*Dy**2 - 2*Ay*Du**2 - 2*Ay*Du*Dy - 2*Ay*Dy**2)/(Dy*(Du**3 - 3*Du**2*Dy + 3*Du*Dy**2 - Dy**3))
d= Dy*(3*Au*Du*Dy - Au*Dy**2 - 2*Ay*Du**2)/(Du**3 - 3*Du**2*Dy + 3*Du*Dy**2 - Dy**3)
Dy = 0.05
Du = 0.5
Ay = 0.2
Au = 1.5
print((a, b, c, d))
Python: (8.779149519890263, 2.798353909465018, 3.786008230452675, 0.004801097393689983)
Excel: (148.1481481, 22.22222222, 8.888888889, 0.018518519)
Surely it must be a simple error, but I cannot find it. In Excel I used "Name a Range" and paste the formulas from Python to avoid writing errors.