Skip to main content

how to use the newton method in the Rachford rice problem?


 



๐Ÿงช๐Ÿ“ˆ Exploring Newton's Method: Solving Rachford-Rice Equation in Python ๐Ÿ


Are you ready to dive into the fascinating world of chemical engineering and numerical methods? Today, we're going to explore how to solve the Rachford-Rice equation using Newton's method in Python. But first, let's set the stage.


## Understanding the Rachford-Rice Equation ๐Ÿ“


The Rachford-Rice equation is a fundamental equation used in chemical engineering to determine the vapor-liquid equilibrium (VLE) of a mixture. It's particularly useful in distillation processes. The equation is derived from Raoult's law and Antoine's equation, both of which describe the vapor pressure of an ideal solution.


## What is Newton's Method? ๐Ÿค”


Newton's method is an iterative numerical technique used to find the roots of a function. In our case, we'll be using it to find the root of the Rachford-Rice equation, which represents the vapor fraction of a mixture. The method involves iteratively improving an initial guess until a desired level of accuracy is achieved.


## Implementing the Solution in Python ๐Ÿ


```python

def rachford_rice(K_values, beta):

    """

    Calculate the Rachford-Rice function.

    

    Args:

    - K_values (list): List of equilibrium constants for each component.

    - beta (float): Liquid phase fraction.

    

    Returns:

    - float: Rachford-Rice function value.

    """

    return sum((K - 1) * beta / (1 + (K - 1) * beta) for K in K_values)


def rachford_rice_derivative(K_values, beta):

    """

    Calculate the derivative of the Rachford-Rice function.

    

    Args:

    - K_values (list): List of equilibrium constants for each component.

    - beta (float): Liquid phase fraction.

    

    Returns:

    - float: Derivative of the Rachford-Rice function.

    """

    return sum((K - 1)**2 / (1 + (K - 1) * beta)**2 for K in K_values)


def solve_rachford_rice(K_values, initial_guess, tolerance=1e-6, max_iter=100):

    """

    Solve the Rachford-Rice equation using Newton's method.

    

    Args:

    - K_values (list): List of equilibrium constants for each component.

    - initial_guess (float): Initial guess for the liquid phase fraction.

    - tolerance (float): Tolerance level for convergence.

    - max_iter (int): Maximum number of iterations.

    

    Returns:

    - float: Liquid phase fraction (beta).

    """

    beta = initial_guess

    iteration = 0

    

    while True:

        f = rachford_rice(K_values, beta)

        f_prime = rachford_rice_derivative(K_values, beta)

        delta_beta = -f / f_prime

        beta += delta_beta

        iteration += 1

        

        if abs(delta_beta) < tolerance or iteration >= max_iter:

            break

    

    return beta


# Example usage

K_values = [1.2, 0.8]  # Equilibrium constants for two components

initial_guess = 0.5     # Initial guess for liquid phase fraction

vapor_fraction = solve_rachford_rice(K_values, initial_guess)

print("Vapor Fraction:", vapor_fraction)

```


## Conclusion ๐ŸŽ‰


In this blog post, we've delved into the world of chemical engineering and numerical methods by exploring how to solve the Rachford-Rice equation using Newton's method in Python. By understanding the fundamentals of the equation and implementing it in code, you can gain insights into vapor-liquid equilibrium and improve your skills in numerical analysis.


Happy coding! ๐Ÿ”ฌ๐Ÿ’ป

 

References

https://onepetro.org/JPT/article/4/10/19/162083/Procedure-for-Use-of-Electronic-Digital-Computers

Comments

Popular posts from this blog

Getting started with FEOS, the framework for Equation of state by iit/univ Stuttgart and eth/zurich

     ๐ŸŒŸ Exploring FEOS: The State-of-the-Art Equation of State Framework by IIT Stuttgart and ETH Zurich ๐ŸŒŸ Hey there, fellow science enthusiasts! ๐Ÿ‘‹ Are you ready to dive into the captivating world of equation of state frameworks? Well, hold onto your lab coats because today, we're exploring FEOS – the cutting-edge framework developed by the brilliant minds at IIT Stuttgart and ETH Zurich! ๐Ÿš€ ### Unraveling the Mysteries of FEOS ๐Ÿ” Equation of state (EOS) plays a pivotal role in various scientific disciplines, ranging from physics and chemistry to material science and engineering. It's the cornerstone for understanding the thermodynamic properties of matter under different conditions. And when it comes to precision and reliability, FEOS stands tall among its peers. ๐Ÿ“ ### The Powerhouse Collaboration: IIT Stuttgart & ETH Zurich ๐Ÿค FEOS is not just another run-of-the-mill framework; it's the result of a powerhouse collaboration between the renowned institutions – IIT ...

creating numerical arrays with logic

  **Title: Navigating Numerical Spaces with NumPy: arange vs linspace vs logspace** When it comes to generating numerical sequences in Python, NumPy offers a plethora of options, each tailored to specific needs. Among these, `arange`, `linspace`, and `logspace` stand out as versatile tools for crafting arrays. Let’s embark on a journey through these functions, exploring their nuances and applications! ๐Ÿš€ ### The Basics: arange NumPy’s `arange` function is akin to Python’s built-in `range`, but with the added capability of generating arrays with non-integer steps. It’s your go-to tool for creating sequences with regular spacing. ```python import numpy as np # Syntax: np.arange(start, stop, step) arr = np.arange(0, 10, 2) print(arr) # Output: [0 2 4 6 8] ``` think of it as points in an closed/open interval [a,b) with step s between each point  ๐Ÿงฉ **Use Case**: When you need control over the step size and want a compact syntax. ### The Uniform Choice: linspace `linspace` divides...

what is @something on a function, i heard it is for decoration?!

  Title: ๐ŸŽจ Exploring Python Decorators: Adding Magic to Your Code! ✨ Python decorators are like the fairy godmothers of programming—they sprinkle a little magic onto your functions, enhancing them with extra functionality. In this blog post, we'll dive into the enchanting world of decorators, exploring how they work and unleashing their powers with two whimsical examples. **Example 1: The Enigmatic @echo Decorator** Imagine a decorator that echoes the inputs and outputs of a function, adding a touch of sparkle to the console. Behold, the @echo decorator! ```python def echo(func):     def wrapper(*args, **kwargs):         print("✨ Echoing inputs:")         for arg in args:             print(f"\t- {arg}")         result = func(*args, **kwargs)         print("✨ Echoing output:")         print(f"\t- {result}")         return re...