Finding volume (van der waal eos) c++

  • C/C++
  • Thread starter Lord Dark
  • Start date
  • Tags
    C++ Volume
In summary, the equation for the volume of a gas is p~=~\frac{r~t}{v - b} - \frac{a}{v^2} and you need to do some algebra to solve it.
  • #1
Lord Dark
121
0
Hi guys ,,

I made a program to find the volume/mol using van der waals EOS

/* following equation is van der waals eos which gives you the volume per mol */

#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main ()
{
double p, // pressure in KPa
v, // volume in meter cubed
r, // gas constant or universal constant
t, // tempreture in kelvin
a,b, // van der waals constants
tcr,pcr ;// the critical points of the pressure & tempreture

r = 8.318 ;

cout << " Enter the value of pressure in KPa = " ;
cin >> p ; cout << endl ;
cout << " Enter the value of the tempreture in Kelvin = " ;
cin >> t ; cout << endl ;
cout << " Enter the value of the pressure critical point in Kpa = ";
cin >> pcr ; cout << endl ;
cout << " Enter the value of the temrpeture critical point in K = ";
cin >> tcr ; cout << endl ;

a = (27*pow(r,2)*pow(tcr,2))/(64*pcr);
b = (r*tcr)/(8*pcr);

p = ((r*t)/(v-b)) - (a/pow(v,2)) ;

cout << " The value of the Volume in m3/mol = " << v ;

return 0;
}

I know that my mistake is in
p = ((r*t)/(v-b)) - (a/pow(v,2))
the problem is that I can't let v be alone ,, so can anyone help me to find a way to slove for v ??
 
Technology news on Phys.org
  • #2
You can't set p to a value that depends on v, which is uninitialized, so what will happen is that the value that was input for p will be overwritten by a garbage value.

You need to do some algebra first. You have
[tex]p~=~\frac{r~t}{v - b} - \frac{a}{v^2}[/tex]

which I assume is the correct equation.

If you multiply both sides of this equation by v2(v - b), you get this equation:
[tex]p~v^2(v - b)~=~r~t~v^2 - a(v - b)[/tex]

Simplifying and moving terms around results in the following equations:

[tex]p~v^3 - p~b~v^2 - r~t~v^2 + a~v + a~b = 0[/tex]

[tex]v^3 - (b + \frac{r~t}{p})v^2 + \frac{a}{p}v + \frac{a~b}{p} = 0[/tex]

Unfortunately, this is a third-degree equation in v. There are ways to solve cubics, but they are fairly involved and aren't too well known.
 
  • #3
so I can't use c++ for Cubic equations right ??

can you recommend a program that will work with cubic equations ??
 
  • #4
iirc, MATLAB or mathematica can do that job.
 
  • #5
Lord Dark said:
so I can't use c++ for Cubic equations right ??

can you recommend a program that will work with cubic equations ??
Nor can you use C++, C, C#, Fortran, Basic, and most other programming languages to solve quadratic or even linear equation. They aren't programs; they are general purpose programming languages that you can use to write programs.
 
  • #6
Ok ,, I guess I'll try mathematica .

Thanks very much guys :)
 

1. What is the van der Waals equation of state?

The van der Waals equation of state is a mathematical expression that describes the behavior of real gases, taking into account the size of gas particles and the attractive forces between them. It is an improvement over the ideal gas law, which assumes that gas particles have no volume and do not interact with each other.

2. How is the van der Waals equation of state different from the ideal gas law?

The ideal gas law assumes that gas particles have no volume and do not interact with each other, while the van der Waals equation takes into account the volume of gas particles and the attractive forces between them. This makes the van der Waals equation more accurate in describing the behavior of real gases at high pressures and low temperatures.

3. What is the formula for finding volume using the van der Waals equation of state in C++?

The formula for finding volume using the van der Waals equation of state in C++ is: V = (nRT)/(P + a(n/V)^2)(V - nb), where V is the volume, n is the number of moles, R is the gas constant, T is the temperature, P is the pressure, a is a constant that takes into account the attractive forces between gas particles, and b is a constant that takes into account the volume of gas particles.

4. Can the van der Waals equation of state be used for all types of gases?

No, the van der Waals equation is most accurate for gases that have a relatively high molecular weight and a relatively low critical temperature. It is not suitable for gases such as hydrogen and helium, which have low molecular weights and high critical temperatures.

5. What are some potential sources of error when using the van der Waals equation of state in C++?

Some potential sources of error when using the van der Waals equation of state in C++ include not using the correct values for the constants a and b, not accounting for the non-ideal behavior of real gases at high pressures and low temperatures, and not considering other factors such as intermolecular forces or the presence of impurities in the gas. It is important to carefully select appropriate values for the constants and to understand the limitations of the equation in order to minimize errors.

Similar threads

  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
2
Views
802
  • Programming and Computer Science
Replies
4
Views
1K
  • Advanced Physics Homework Help
Replies
6
Views
2K
Back
Top