MATLAB: Programmatic polynomial fitting with mutliple measurements and known parameters

polyfit multiple regression modelling polynomial model

I am not new to Matlab, but very new to polynomial modelling of data. I have a set of measurements for observed solubility with specific parameters being changed. There are four parameters that can be experimentally varied.
I have made measurements with 7 different possible values for 3 of the 4 parameters and 10 possible values for the remaining 1 parameter. Therefore my response variable data is a matrix of 70 values (7×10). corresponding to the 10 values for parameter x4 with different values for parameters x1,x2,x3.
Here is what the data looks like:
x1: 1.92683450920000 1.82794091830000 2.01642468230000 1.75600069780000 1.75466924060000 1.83419721490000 1.84217366130000
x2: 275 160 26 76 30 133 107
x3: 0 22 42 40 67 80 100
x4: 100 90 80 70 60 50 40 30 20 10
The responses (7×10) correspond to an experimental condition where the row index is the value from x1,x2,x3,and the column index is the value of x4 used. For practical reasons exhaustive parameter isolation is not possible.
Seems like a simple regression problem, but I can't quite get matlab and polyfit, also tried the polyfitn function to stop complaining about the asymmetry of x variables.
The objective is to determine if (and which) polynomial model best fits the data and describes the reaction.
Any help would be greatly appreciated.
–m

Best Answer

If I understand this correctly, you want model something as y = f(x1,x2,x3,x4), where f is a polynomial of some sort.
You have 70 data points, and if we call your 7x10 response matrix y, then it is arranged like this:
f(1.92, 275, 0, 100) -> y(1,1)
f(1.92, 275, 0, 90) -> y(1,2)
f(1.92, 275, 0, 80) -> y(1,3)
.
.
f(1.82, 160, 22, 100] -> y(2,1)
f(1.82, 160, 22, 90] -> y(2,2)
f(1.82, 160, 22, 80] -> y(2,3)
.
.
f(1.84, 107, 100, 10) -> y(7,10)
In that case, the first step is to put your x's into a 70x4 matrix like this.
x1=[ 1.92683450920000 1.82794091830000 2.01642468230000 1.75600069780000 1.75466924060000 1.83419721490000 1.84217366130000];
x2=[275 160 26 76 30 133 107];
x3=[ 0 22 42 40 67 80 100];
x4=[ 100 90 80 70 60 50 40 30 20 10];
X = [];
for n = 1:7;
X = [X; repmat([x1(n) x2(n) x3(n)],10,1)];
end;
X(:,4) = repmat(x4',7,1);
Now X is a 70x4 matrix representing your inputs.
Next turn your 7x10 matrix y into a 70x1 column vector representing your results.
Y = y(:);
Now there are many ways to fit depending of what form of f you want to use. If you have the latest release of MATLAB along with the Statistics Toolbox installed, a simple first order linear model could be solved like this:
LinearModel.fit(X,Y)
This yields a model of the form y = A*x1 + B*x2 + C*x3 + D*x4 + E
For higher order polynomials, see the help for LinearModel.fit.