Multi-variable non linear regression

2 次查看(过去 30 天)
Vick
Vick 2017-8-30
编辑: dpb 2017-8-31
Hello all,
Problem Definition:
I've a 2D table which are the coefficients which has to be solved using non linear multi variable regression. Objective:
To get the Air flow at any given pressure and temperature. Problem: Air flow=Pressure.*Volume.* correction factor./Temperature
Here the correction factor depends on both Pressure and Temperature. So it is a 2D table. If Pressure is 1 bar and temperature is 25 Deg C. The output scalar should be interpolated from the correction 2D table.
The data is collected for 1 hour at different temperature and pressure and the air flow is also measured using flow meter. So now we have a Pressure, temp, volume and air flow. we have to find the correction factor table.
I've written something like this.
function out=sury(data,coeff)
correction_map_Pressure=[0.97,0.98,0.99,1.00,1.01,1.02,1.03];
correction_map_Temperature=[24,25,26,27];
correction_coeff=[coeff(1),coeff(2),coeff(3),coeff(4),coeff(5),coeff(6),coeff(7);
coeff(8),coeff(9),coeff(10),coeff(11),coeff(12),coeff(13),coeff(14);
coeff(15),coeff(16),coeff(17),coeff(18),coeff(19),coeff(20),coeff(21);
coeff(22),coeff(23),coeff(24),coeff(25),coeff(26),coeff(27),coeff(28)];
Pressure=data(:,1);
Temperature=data(:,2);
Volume=20;
correction_factor=interp2(correction_map_Pressure,correction_map_Temperature,correction_coeff,Pressure,Temperature);
out=Pressure.*Volume.*Correction_factor*/Temperature;
end
Data(:,1)=(1.03-0.97)*.rand(1000,1)+0.97;
Data(:,2)=(27-24)*.rand(1000,1)+24;
Airflow=(10-13)*.rand(1000,1)+10;
Predicted_coeff=rand(28,1);
OUTPUT=fitnlm(Data,Airflow,@sury,Predicted_coeff);
My actual problem have more than 200 coefficients like this and the size of data is more than 10000 rows. Is this correct way of solving this equation?
  3 个评论
Vick
Vick 2017-8-30
编辑:Vick 2017-8-30
Hi dpb, Your first point is correct.. There will be multiple measurement as, the pressure will be increasing in transient condition at some constant temperature and the same measurement will go on for different temperatures.
On interpolation function i'm clear with interp2, If i have the constants as a single scalar value instead of 2D table, fitnlm function will work for sure, Since the interpolation is there inside the function i'm confused weather this fitnlm will work or not, OR any different solution for this kind of problem?
dpb
dpb 2017-8-30
编辑:dpb 2017-8-31
fitnlm estimates the coefficients of the modelfun argument
y ~ f(b,x).'
where b is the vector of coefficients and x is a matrix of the same number of columns as predictor variables (P,T,V or three here).
The problem here is that you're trying to estimate some 28 coefficients with only two independent variables. There aren't enough DOF to do that to fit each correction factor independently.
You could use an nonlinear least squares model to fit the best average factor but if you're simply computing the observed factor at each point there's no model per se, just the individual observations.
There's nothing that says inherently you can't estimate over the 2D array as written but you'll have to structure the interface to the function to match the form fitnlm expects which is the vector and do the transform to/from 1D-2D-1D inside the function.
function out=sury(X,y,coeff)
P=[0.97:0.01:1.03];
T=[24:27];
coeff=reshape(coeff,7,[]).';
Pressure=X(:,1);
Temperature=X(:,2);
Volume=20;
CF=interp2(P,T,coeff,Pressure,Temperature);
out=Pressure.*Volume.*CF./Temperature;
out=out(:);
end
I shortened variable names for conciseness and used Matlab syntax for the various operations instead of writing them out explicitly.
The actual corrections were to
  1. fix the typo of "*/" for the intended "./"
  2. insert the required response variable into the argument list, and to
  3. recast the output to the vector form expected by fitnlm instead of the 2D array.
That will, however, still not work owing to the problem outlined above of not having the sufficient DOF to estimate 28 coefficients from two variables.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by