0

I am trying to use Cantera to solve some thermodynamics problems. I cannot get this function to solve for b1, c1, d1, and e1 as functions of phi_rich. Basically I need to find these values at each value of Phi_rich. My function will not work.

Here is my code:

import numpy as np

phi_rich = phi[10:20] # Pulls final 10 values of phi array

b1 = np.zeros(phi_rich.shape)


c1  = np.zeros(phi_rich.shape)

d1 = np.zeros(phi_rich.shape)

e1 = np.zeros(phi_rich.shape)

def func(b1,c1,d1,e1):

  
    
    ## Now Calculate Fuel Rich
    phi_rich = phi[10:20]
    x = 3
    y = 8
    a_rich =((x+(y/4))/phi_rich)     

   
    
    return[ (c1 + d1 - 2*a_rich)/2, 3 - b1, 4 - e1, x + (y/2) - b1 - c1 - d1]

result = optimize.fsolve(func,(0.1, 0.1, 0.1, 0.1))

I included this to help explain my problem. I am trying to set up a python function to solve for each of these values (a,b,c,d, and e) using an array of Phi values (10 to be exact):

Will
  • 21
  • 2
  • What's the question? Where are you getting stuck? [Images](//meta.stackoverflow.com/q/285551/90527) should not be used for textual data, such as formulae. Please include sample data to make your [mcve] complete. Note that if you want the last 10 items of a sequence, you can use negative indices (e.g. `phi[-10:]`), which will work no matter the size of a (finite) sequence. – outis May 10 '22 at 21:27
  • My apologies, I have updated it to reflect my question – Will May 10 '22 at 21:38

1 Answers1

0

Your system is linear in the unknowns. You can re-write your system of equations as an augmented matrix and then put it into reduced row echelon form. This will tell you

  1. whether solutions exist,
  2. whether there is a finite or infinite number of solutions if they exist,
  3. and what the unique solution is if there is one.

SymPy provides a method rref to its Matrix class. So instantiate your augmented matrix object with that class, and call the method on it. See example:

Note that for a fixed value of $a$ along with $x$ and $y$, equation one cannot be satisfied for differing values of $\Phi$. But you can take the above approach for each distinct value of $\Phi$.

Galen
  • 1,128
  • 1
  • 14
  • 31