Calculate pressure of a real gas using Van der Waal's Equation - GeeksforGeeks

21 Apr, 2021
Given integers V, T, and n representing the volume, temperature and the number of moles of a real gas, the task is to calculate the pressure P of the gas using Van der Waal’s Equation for real gas.
Van der Waal’s Equation for Real Gas:( P + a * n2 / V2 ) * (V – n * b) = n R T) where, average attraction between particles (a) = 1.360, volume excluded by a mole of particles (b) = 0.03186, Universal Gas constant (R) = 8.314
Examples:
Input: V = 5, T = 275, n = 6Output: 2847.64
Input: V = 7, T = 300, n = 10Output: 3725.43
Approach: To solve the problem, simply calculate the pressure P of real gas by using the equation P = ((n * R * T) / (V — n * b)) — (a* n * n) / (V * V) and print the result. 
Below is the implementation of the above approach:
C++
Java
Python3
C#
Javascript
// C++ Program to implement// the above approach #include <bits/stdc++.h>using namespace std; // Function to calculate the pressure of a// real gas using Van der Wall's equationvoid pressure_using_vanderwall(double V,                               double T, double n){     double a = 1.382;    double b = 0.031;    double R = 8.314;     // Calculating pressure    double P = ((n * R * T) / (V - n * b))               - (a * n * n) / (V * V);     // Print the obtained result    cout << P << endl;} // Driver codeint main(){     double V = 7, T = 300, n = 10;    pressure_using_vanderwall(V, T, n);    return 0;}
// Java program to implement// the above approachclass GFG{     // Function to calculate the pressure of a// real gas using Van der Wall's equationpublic static void pressure_using_vanderwall(double V,                                             double T,                                             double n){    double a = 1.382;    double b = 0.031;    double R = 8.314;      // Calculating pressure    double P = ((n * R * T) / (V - n * b)) -                (a * n * n) / (V * V);      // Print the obtained result    System.out.println(String.format("%.2f", P));} // Driver Codepublic static void main(String[] args){    double V = 7, T = 300, n = 10;         pressure_using_vanderwall(V, T, n);}} // This code is contributed by divyesh072019
# Python3 Program to implement# the above approach # Function to calculate the pressure of a# real gas using Van der Wall's equationdef pressure_using_vanderwall(V, T, n):     a = 1.382    b = 0.031    R = 8.314     # Calculating pressure    P = ((n * R * T) / (V - n * b)) - (a * n * n) / (V * V)     # Print the obtained result    print(round(P, 2)) # Driver codeV, T, n = 7, 300, 10pressure_using_vanderwall(V, T, n) # This code is contributed by divyeshrabadiya07
// C# program to implement// the above approachusing System; class GFG{          // Function to calculate the pressure of a    // real gas using Van der Wall's equation    public static void pressure_using_vanderwall(double V,                                                 double T,                                                 double n)    {        double a = 1.382;        double b = 0.031;        double R = 8.314;               // Calculating pressure        double P = ((n * R * T) / (V - n * b)) -                    (a * n * n) / (V * V);               // Print the obtained result        Console.WriteLine(Math.Round(P, 2));    }          // Driver Code    public static void Main(String[] args)    {        double V = 7, T = 300, n = 10;                  pressure_using_vanderwall(V, T, n);    }}  // This code is contributed by AnkitRai01
<script>    // Javascript program to implement the above approach         // Function to calculate the pressure of a    // real gas using Van der Wall's equation    function pressure_using_vanderwall(V, T, n)    {        let a = 1.382;        let b = 0.031;        let R = 8.314;                // Calculating pressure        let P = ((n * R * T) / (V - n * b)) - (a * n * n) / (V * V);                // Print the obtained result        document.write(P.toFixed(2));    }         let V = 7, T = 300, n = 10;      pressure_using_vanderwall(V, T, n);         // This code is contributed by decode2207.</script>
3725.43
 
Time Complexity: O(1)Auxiliary Space: O(1)
 
divyeshrabadiya07
divyesh072019
ankthon
decode2207
Articles
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Time Complexity and Space Complexity
Docker - COPY Instruction
Time complexities of different data structures
SQL | Date functions
Difference between Min Heap and Max Heap
Implementation of LinkedList in Javascript
Difference between Class and Object
Deploy Python Flask App on Heroku
How compare() method works in Java
SQL | Functions (Aggregate and Scalar Functions)