KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Supose that I want to generate a function to be later incorporated in a set of equations to be solved with scipy nsolve function. I want to create a function like this: xi + xi+1 + xi+3 = 1 in which the number of variables will be dependent on the number of components. For example, if I have 2 components: f = lambda x: x[0] + x[1] - 1 for 3: f = lambda x: x[0] + x[1] + x[2] - 1 I specify the components as an array within the arguments of the function to be called: def my_func(components): for component in components: ..... ..... return f I can't just find a way of doing this. I've to be able to make it this way as this function and other functions need to be solved together with nsolve: x0 = scipy.optimize.fsolve(f, [0, 0, 0, 0 ....]) Any help would be appreciated Thanks! Since I'm not sure which is the best way of doing this I will fully explain what I'm trying to do: -I'm trying to generate this two functions to be later nsolved: So I want to create a function teste([list of components]) that can return me this two equations (Psat(T) is a function I can call depending on the component and P is a constant(value = 760)). Example: teste(['Benzene','Toluene']) would return: xBenzene + xToluene = 1 xBenzene Psat('Benzene') + xToluene Psat('Toluene') = 760 in the case of calling: teste(['Benzene','Toluene','Cumene']) it would return: xBenzene + xToluene + xCumene = 1 xBenzene Psat('Benzene') + xToluene Psat('Toluene') + xCumene*Psat('Cumene
Tags (comma-separated)
Save Edits
Cancel