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

roots

%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)

Best Answer

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()