I'm having some problems here...(adsbygoogle = window.adsbygoogle || []).push({});

Part of an assignment is to find how density of a gas changes as a function of pressure (1 - 700 atmospheres) using Van der Waals. Unless I've really missed the boat, there is no closed form solution for specific volume in that equation,

(p+a/v^2)(v-b)=RT

so a numerical method will need to be used.

I tried using a <for> loop to use Matlab's solve function, but I can't get the blasted thing to accept the variable <p> to operate in the loop.

Anybody have any ideas? IREALLYdon't want to have to calculate the value for density 700 times for each of 2 gases... no... really, I don't.

Code (Text):

% Nitrogen

% density variable = rho_N

% a=179.65

% b=.001398

% m=28

% R=8314

% T=298.15

for p=[1:700] % atmospheres

FLAG=false; % Catch multiple real answers

% (p*Pascals/atm + a/v^2)*(v-b) = R/m*t

v=solve('(p*1.01*10^5+179.65/v^2)*(v-.001398)=8314/28*298.15');

for i=[1:length(v)] % find real component

if isreal(v(i))

if FLAG==true; %Catch multiple solutions

error('multiple real solutions for N2 VdW')

end

rho_N(p)=1/v(i);

FLAG==true;

else % No reals error

p

error('no real solutions for N2 VdW')

end

end

end

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# MATLAB & Van der Waals

Loading...

Similar Threads - MATLAB Waals | Date |
---|---|

How to program this in Matlab | Feb 28, 2018 |

Matlab Making a short test for self-adjointness | Feb 23, 2018 |

Matlab Plotting Coordinate Transformations in Matlab | Feb 12, 2018 |

**Physics Forums - The Fusion of Science and Community**