Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Finding volume (van der waal eos) c++

  1. Nov 14, 2009 #1
    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. jcsd
  3. Nov 14, 2009 #2

    Mark44

    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
    [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.
     
  4. Nov 14, 2009 #3
    so I can't use c++ for Cubic equations right ??

    can you recommend a program that will work with cubic equations ??
     
  5. Nov 14, 2009 #4
    iirc, matlab or mathematica can do that job.
     
  6. Nov 14, 2009 #5

    Mark44

    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.
     
  7. Nov 14, 2009 #6
    Ok ,, I guess I'll try mathematica .

    Thanks very much guys :)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook