# Need help on a numerical methods homework, nonlinear regression

Here's the question:

Employ nonlinear regression and the following set of pressure-volume data to find the best possible virial constants (A1 and A2) for the equation of state shown below. R = 82.05 mL atm/gmol K and T = 303 K.

Data of P and V

Now, I'm currently trying to use the Gauss-Newton method, which uses this equation:

Matrix Form for Gauss-Newton

Now, I've reiterated the given formula to:

$$P=RT/V+ A1/V^2+A2/V^3$$

So, P will act as the y-axes, and V will act as the x-axes. I've also defined the Z matrix, filling it with $$\frac{\partial P}{\partial A1}$$ as the first column and $$\frac{\partial P}{\partial A2}$$ as the second column. Here is the snippet of the code in MATLAB:

Code snippet 1

Now, I'm confused as to how do I fill the D matrix. Based on Chapra's Numerical Methods book, I found this formula from an example:

Finding D

Now it's written in the book that the D matrix is filled with the difference between measurements and the model prediction. Now my confusion lies in how can $$\frac{\partial f}{\partial a0}$$ serve as the model prediction?

To sum up, here are my questions:

1. How can $$\frac{\partial f}{\partial a0}$$ serve as the model prediction?
2. Am I on the right track in finding the constants for A1 and A2 by using the Gauss-Newton nonlinear regression method?

No, you are not since $$P=\frac {RT}V+\frac{A_1}{V^2}+\frac{A_2}{V^3}$$ is linear with respect to $$(A_1,A_2)$$.

You just face a linear regression writing $$V^3\left(P-\frac {RT}V \right)=A_1\,V+A_2$$ This can be done by hand (I did it with my phone).

• Hi Claude ! We meet again. I'm beat by a few minutes. Cheers. May 15 at 8:08

The result depends on the quantity of gaz N = gmol which is not given in the wording of the problem. In order to clarify a first linear regression is carried out : Probably N=1 was implicit. Now we can compute A1 and A2 thanks to linear regression : • Hi Jean ! I think that we very often meet for this kind of problem ! Cheers :-) May 15 at 8:16