I don't know what's wrong with my codes. There's no answer to the roots volume in the command window. Please help

Asked by mscv about 9 hours ago
Latest activity Commented on by Roger Stafford about 6 hours ago
%Determine the volume of the gas using van der Waals equation if the
%cylinder tank is to be filled up with 170 g-mol of CO2 to a pressure of 65
%atm and -70 C.
N = 170;
P = 65;
T = -70 + 273; %Celsius to Kelvin conversion
Tc = 304.2;
Pc = 73.83*0.986923; %bar to atm conversion
R = 0.08205;
%Equation of State Parameters
a = (27*R^2*Tc^2)/(64*Pc);
b = (R*Tc)/(8*Pc);
%van der Waals Equation (fzero)
x = @(V)((P + (N^2*a)/V^2)*(V - N*b) - N*R*T);
z = fzero(x,30);
%van der Waals equation in terms of a third degree polynomial equation
%(roots)
vdW = (P - (P*N*b + N*R*T) + a*N^2 - a*b*N^3);
r = roots(vdW);
fprintf('fzero Volume (in L): %8.3f \n', z)
fprintf('roots Volume (in L): %8.3f\n', r) 

0 Comments

mscv

Tags

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson about 6 hours ago

Everything in vdW has exact numeric values, and none of the variables are vectors. vdW is therefore a numeric scalar. If the numeric scalar is non-zero, then roots() of it is non-existant, equivalent to asking for the roots of y = 17.

If you are intending N to be the unknown in the equation, then construct as follows:

vdW = [-a*b, a, -(P*b + R*T), P];

Notice that N, the value to be found, is not explicitly mentioned in the matrix to be passed to roots()

1 Comment

Roger Stafford about 6 hours ago

Actually 'V' is mscv's desired unknown and the coefficients of the appropriate cubic in V have been correctly calculated. The mistake here is that these coefficients have been added together rather than separated, as Walter states. The 'roots' function has no way to disentangle these coefficients from their sum.

Walter Roberson

Contact us