0

I am trying to solve the system of equations using the below code to get the value of Ca, Cb, Cc, and Cd. However, I just got the void blank. I don't know what I made a mistake. Please help me modify the below code to get the proper answer. Anything you could do for me would be highly appreciated.

import sympy as sp

Ca, Cb, Cc, Cd = sp.symbols('Ca, Cb, Cc, Cd')
k1a = 10
k2c = 15
ra = -k1a*Ca*(Cb**2)+(2/3)*(-k2c*(Ca**2)*(Cc**3))
rb = -2*k1a*Ca*Cb**2
rc = k1a*Ca*Cb**2+(-k2c*(Ca**2)*(Cc**3))
rd = (-1/3)*(-k2c*(Ca**2)*(Cc**3))
eq1 = sp.Eq(2500, (100*Ca-100*2)/ra)
eq2 = sp.Eq(2500, (100*Cb-100*2)/rb)
eq3 = sp.Eq(2500, (100*Cc)/rc)
eq4 = sp.Eq(2500, (100*Cd)/rd)

R = sp.solve((eq1, eq2, eq3, eq4), (Ca, Cb, Cd, Cd))
print(R)
Ji Chul
  • 17
  • 3
  • These equations are really much too hard to solve with sympy. For some reason sympy returns an empty array instead of telling so. (Also, in your code you call `sp.solve` with `Cd` twice, but correcting that typo unfortunately won't influence the result). – JohanC Apr 28 '20 at 18:06
  • Thank you for your kind comment. Do you happen to know the way to solve this kind of equations with Python? – Ji Chul Apr 29 '20 at 19:09
  • I tried with the approach from [this post](https://stackoverflow.com/questions/40783190/solve-a-system-of-non-linear-equations-in-python-scipy-optimize-fsolve), but that also didn't find good approximations. It could help if you have good initial guesses for the 4 parameters. – JohanC Apr 29 '20 at 19:31
  • Also `R = sp.nsolve((eq1, eq2, eq3, eq4), (Ca, Cb, Cc, Cd), (1, 1, 1, 1))` would be a possibility, but (1,1,1,1) isn't a workable initial guess. – JohanC Apr 29 '20 at 19:37
  • I just found the initial guess (1, 1, 0.1, 0.1) works properly. Many thanks, JohanC. You are great help to me. – Ji Chul Apr 30 '20 at 16:06

0 Answers0