# Newton-Raphson Root Finding, Difficulty in coding

GROUPS:
 Hello, I seem to be having trouble writing for a problem I'm having.  I need to find Specifi Volumes of Carbon Dioxide from the Van der Waals equation, using the Newton method, over a process of constant Temperature and variant Pressure.  I am using Mathematica; I'm not very strong at coding in general and am fairly new to Mathematica.  I have figured out how to find a single value for the Specific Volume given a set Pressure.  However I am having trouble coding over the pressure change. I want The pressure to change from 3.9atm to 59atm.  Another issue I seem to be having is it spits our odd answers for Specific Volume if the Temperature is above 329 or the Upper limit of Pressure is above 55.  I need T=333K and the upper Pressure=59.2.  Here is my code and output, the example pressure is at 10atm: a = 1.36; b = .003183; R = .0820578; T = 329; P = 10; atmA = 3.9; atmB = 59.21;  F[vi_] = vi - {{P + {a/vi^2}} {vi - b} - {R*T}}/{P - {a/vi^2} + {2 a*       b/vi^3}}FindRoot[F[vi] == 0, {vi, 5}, WorkingPrecision -> 5]{{{-((-26.997 + (10 + 1.36/vi^2) (-0.003183 + vi))/(     10 + 0.00865776/vi^3 - 1.36/vi^2)) + vi}}}{vi -> 2.6512}Ignoring these previous issues, my attempt to solve the problem was to use a double integral.  However that has gotten nowehere. a = 1.36; b = .003183; R = .0820578; T = 329; atmA = 3.9; atmB = 59.21;  Integrate[  vi - {{P + {a/vi^2}} {vi - b} - {R*T}}/{P - {a/vi^2} + {2 a*       b/vi^3}}, {p, atmA, atmB}, {vi, 0, p}]{{{4652.6 + 63.0819 I}}}Thanks for your help.  I know I'm very lost and attempting to teach me may be a hurdle
4 years ago
4 Replies
 Jari Kirma 2 Votes First of all, try replacing curly braces in your equations (but not in FindRoot or two last arguments of Integrate!) with regular paretheses ( "(" and ")" ). Also, replace = in your definition of F with := .Curly braces construct lists in Mathematica. Also, when you attempt to define a function, you almost certainly want to use := which is delayed assignment - = is not delayed. Some of the strange output you see is caused by this.I cannot really comment your actual task in itself, but I suspect something domain-specific is wrong either with your equations, or input parameters. If we do the integration symbolically:Integrate[vi - ((P + (a/vi^2)) (vi - b) - (R T))/(P - (a/vi^2) + (2 a b/vi^3)),  {p, a1, a2}, {vi, 0, p},  Assumptions -> 0 < a1 < a2](* ConditionalExpression[(-0.0093055 - 1.35144 a1) a1 + a2 (0.0093055 + 1.35144 a2) + (9.66322*10^-8 - 0.0000151749 a1) Log[0.0063679 - 1. a1] + (0.132705 - 0.363022 a1) Log[0.365557 - 1. a1] + (0.236186 + 0.635037 a1) Log[0.371924 + 1. a1] + (-9.66322*10^-8 + 0.0000151749 a2) Log[0.0063679 - 1. a2] + (-0.132705 + 0.363022 a2) Log[0.365557 - 1. a2] + (-0.236186 - 0.635037 a2) Log[0.371924 + 1. a2], a2 < 0.0063679] *)The logarithms easily indicate that you are going to get complex-valued result if you input anything higher than 0.0063679 to your pressure range.