# Finding volume (van der waal eos) c++

1. Nov 14, 2009

### Lord Dark

Hi guys ,,

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

I know that my mistake is in
the problem is that I can't let v be alone ,, so can anyone help me to find a way to slove for v ??

2. Nov 14, 2009

### Staff: Mentor

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
$$p~=~\frac{r~t}{v - b} - \frac{a}{v^2}$$

which I assume is the correct equation.

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

Simplifying and moving terms around results in the following equations:

$$p~v^3 - p~b~v^2 - r~t~v^2 + a~v + a~b = 0$$

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

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. Nov 14, 2009

### Lord Dark

so I can't use c++ for Cubic equations right ??

can you recommend a program that will work with cubic equations ??

4. Nov 14, 2009

### ApexOfDE

iirc, matlab or mathematica can do that job.

5. Nov 14, 2009

### Staff: Mentor

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. Nov 14, 2009

### Lord Dark

Ok ,, I guess I'll try mathematica .

Thanks very much guys :)