Multi-variable non linear regression
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
dpb
le 30 Août 2017
Modifié(e) : dpb
le 31 Août 2017
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
- fix the typo of "*/" for the intended "./"
- insert the required response variable into the argument list, and to
- 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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!