Multi Variable Non-linear Curve Fitting in MATLAB

159 vues (au cours des 30 derniers jours)
M Fahd
M Fahd le 11 Fév 2019
Dear all,
I am trying to curve fit my objective variable "tau" which is called Ignition delay (unit, milli-sec). tau is modeled as a function of three variables as listed below
  1. Temperature, T (K),
  2. Pressure, P (atm), and
  3. Equivalence ration, phi (unitless)
The proposed curve-fitting equation has the following form. Here, a, b, c, d, e are the curve-fitting constant. And, here i = 3. Therefore, in total there is 15 curve-fitting constants.
tau(i) = ai * (p^bi) * (T^ci) * EXP(di / T) * (phi^ei)
Can anyone please suggest which MATLAB curve-fitting/regression tool should I use? Thanks in advance. I have attached a test data file if anyone is interested. Thanks.
****
Ultimate expression for the tau (if anyone is interested why i is set to be 3)
tau = (tau-1 + tau-2 + tau-3) / { (tau-1+tau-2) * tau-3 }

Réponse acceptée

Star Strider
Star Strider le 11 Fév 2019
I would do this:
[D,S] = xlsread('Data_Source.xlsx');
EPT = D(:,1:3);
tauv = D(:,4);
% tau(i) = ai * (p^bi) * (T^ci) * EXP(di / T) * (phi^ei)
taufcn = @(b,x) b(1) * x(:,2).^b(2) .* x(:,3).^b(3) .* exp(b(4)./x(:,3)) .* x(:,1).^b(5);
[B,R,J,CovB] = nlinfit(EPT,tauv,taufcn,rand(5,1));
BCI = nlparci(B,R,'covar',CovB);
You can have a matrix independent variable in all curve-fitting and optimization applications in MATLAB. You simply have to refer to the individual columns of the matrix as the different independent variables. (Here, they are ‘EPT’=[‘Equivalence Ratio’, ‘Pressure’, ‘Temperature’]), so ‘x(:,1)’ is ‘Equiv. Ratio’, and so for the others), with ‘tau’ as the single dependent variable.
I also calculate the parameter confidence intervals in this code, finding that ‘b(1)’ is not significantly different from zero, and so is not needed in the model. The others are all significant.
Experiment to get the result you want.
  3 commentaires
Star Strider
Star Strider le 11 Fév 2019
As always, my pleasure.
Miraboreasu
Miraboreasu le 27 Nov 2022
@Star Strider Hello, sorry to bother you, I am using nlinfit, I have 2 variable, so I cannot plot 2D to see if the fitting is fine, so should I sum up the R? or how to evaluate the my fitting?

Connectez-vous pour commenter.

Plus de réponses (3)

Stephan
Stephan le 11 Fév 2019
Modifié(e) : Stephan le 11 Fév 2019
Hi,
i suggest to model this as a system of 4 equations with the 15 unknownse and use . 3 equations to calculate the tau(i) values and the 4th equation to calculate tau from the results of equations 1-3. Then subtract the measured value for tau from the result of equation 4. This is a job for fsolve.
Best regards
Stephan
  1 commentaire
M Fahd
M Fahd le 11 Fév 2019
Dear Stephan, thanks for the reply. I will try to implement your suggestion along with what Star Strider suggested below. Thank you.

Connectez-vous pour commenter.


Alex Sha
Alex Sha le 3 Août 2019
Hi, Fahd , refer to the results below:
Root of Mean Square Error (RMSE): 1.09231944926872
Sum of Squared Residual: 1355.43178122881
Correlation Coef. (R): 0.999883881381431
R-Square: 0.999767776246396
Adjusted R-Square: 0.999766954942228
Determination Coef. (DC): 0.999758349281268
Chi-Square: 190.539760828559
F-Statistic: 331766.054300988
Parameter Best Estimate
---------- -------------
a1 0.509520813430713
b1 -0.410333298909599
c1 -1.88156624504009
d1 11326.3070797332
e1 -0.0582321791543802
a2 3.53682438415215E-6
b2 0.378224086620891
c2 -2.32994413523028
d2 19151.2160516163
e2 -0.0238944122916122
a3 2.16069394348543
b3 -0.87187579659814
c3 -0.258436168897444
d3 3550.15220868462
e3 -2.03331105345266
tu39.jpg
tu38.jpg
  3 commentaires
harsh Brar
harsh Brar le 9 Mai 2022
Hey Alex sha... Can you please share the code?
Pedro Machado
Pedro Machado le 18 Juil 2022
Hi @Alex Sha, can you please share the full code you used? Thanks!!

Connectez-vous pour commenter.


S0852306
S0852306 le 23 Juil 2023
The fitted surface matches your data quite well:
root mean square error : 0.1482
sum of square error : 24.9477
mean absolute error : 0.0971
code: (to run this script, download the toolbox at file exchange : https://tinyurl.com/wre9r5uk)
clear; clc; close all;
T=readtable("Data_Source.xlsx");
%%
data(1,:)=T.Equiv_Ratio_Phi';
data(2,:)=T.Pressure_P_atm_';
data(3,:)=T.Temperature_T_K_';
label=T.IDT_Tau_milli_sec_';
%%
NN.InputAutoScaling='on'; NN.LabelAutoScaling='on';
InSize=3; OutSize=1;
LayerStruct=[InSize,10,10,10,OutSize];
NN=Initialization(LayerStruct,NN);
%%
option.MaxIteration=1500;
NN=OptimizationSolver(data,label,NN,option);
Stats
R=FittingReport(data,label,NN);
%%
figure
p=NN.Evaluate(data); % use this function to evaluate fitted model
plot(label,'.')
hold on
plot(p)
legend('target value','fitted n-d surface')
% SSE=sum(R.ErrorVector.^2); % MSE=mean(R.ErrorVector.^2); % RMSE=sqrt(MSE)
The model I used is a neural net, it's a universal approximator (able to approximate any continuous function given
enough parameters), although it has a fancy name, its mathematical model is actually quite simple.
Detail math info can be found at file exchange website.

Catégories

En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by