Finding volume (van der waal eos) c++

  • Context: C/C++ 
  • Thread starter Thread starter Lord Dark
  • Start date Start date
  • Tags Tags
    C++ Volume
Click For Summary

Discussion Overview

The discussion revolves around solving for volume per mole using the van der Waals equation of state (EOS) in a C++ program. Participants explore the challenges of isolating the volume variable in a cubic equation derived from the EOS.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant presents a C++ program intended to calculate volume per mole using the van der Waals EOS but encounters difficulty isolating the volume variable.
  • Another participant points out that the equation for pressure depends on an uninitialized volume, leading to potential errors in the program.
  • A mathematical transformation of the original equation is provided, resulting in a cubic equation in terms of volume.
  • There is a discussion about the feasibility of solving cubic equations in C++, with suggestions that other software like MATLAB or Mathematica may be more suitable for this task.
  • One participant expresses uncertainty about using C++ for cubic equations and seeks recommendations for alternative programs.

Areas of Agreement / Disagreement

Participants generally agree on the challenges of solving cubic equations in C++ and suggest alternative software solutions. However, there is no consensus on the best approach to take within C++ itself.

Contextual Notes

The discussion highlights the complexity of solving cubic equations and the limitations of general-purpose programming languages for specific mathematical problems.

Who May Find This Useful

Individuals interested in computational methods for solving equations, particularly in the context of physical chemistry or programming in C++. Also, those exploring alternative software for mathematical computations.

Lord Dark
Messages
120
Reaction score
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 ;

count << " Enter the value of pressure in KPa = " ;
cin >> p ; count << endl ;
count << " Enter the value of the tempreture in Kelvin = " ;
cin >> t ; count << endl ;
count << " Enter the value of the pressure critical point in Kpa = ";
cin >> pcr ; count << endl ;
count << " Enter the value of the temrpeture critical point in K = ";
cin >> tcr ; count << 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)) ;

count << " 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
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.
 
so I can't use c++ for Cubic equations right ??

can you recommend a program that will work with cubic equations ??
 
iirc, MATLAB or mathematica can do that job.
 
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.
 
Ok ,, I guess I'll try mathematica .

Thanks very much guys :)
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 13 ·
Replies
13
Views
8K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
6
Views
3K
Replies
1
Views
2K