How do I fit two power law varying independent variables ( X1 and X2) in the form Y= Constant * X1^n1 * X2^n2. Appreciate the solution with an example for simple data

11 visualizaciones (últimos 30 días)
I am trying to fit tow Power law based variables x1 and x2 in the form of Y=constant * (x1^n1) * (x2^^n2). Kindly suggest the way forward. Kumar RK
  1 comentario
dpb
dpb el 10 de Feb. de 2017
Which toolboxes do you have available? If have Curve Fitting Toolbox, there are examples of using the interactive tool to fit custom nonlinear models; follow along there and modify to match your own specific form should be able to get you going...

Iniciar sesión para comentar.

Respuestas (2)

John D'Errico
John D'Errico el 10 de Feb. de 2017
Editada: dpb el 11 de Feb. de 2017
As dpb says, the curvefitting TB allows you to fit that model. If you lack that TB, then you can use other tools, like the optimization or stats TB.
Note that a very simple transformation allows you to get pretty good estimates of the parameters in that model. Just take the log. Then your model becomes linear.
log(y) = log(constant) + n1*log(x1) + n2*log(x2)
for that model, giving you good estimates for starting values. Or possibly, this may be the right way to do the fit, if y spans several orders of magnitude. In that case, additive Gaussian noise is probably not a good assumption, but proportional noise will make sense. (Nonlinear regression tools implicitly assume additive Gaussian noise.) Then taking the log transforms a proportional noise structure into additive noise.
  3 comentarios
dpb
dpb el 11 de Feb. de 2017
Well, you didn't give us the input to know what you've got at your disposal...what's wrong with the CF'ing Toolbox methodology???
John D'Errico
John D'Errico el 11 de Feb. de 2017
Editada: John D'Errico el 11 de Feb. de 2017
Gosh, I did not know it was impossible to fit a model to the log problem, and then convert back. I guess I'll need to remember how to solve for C, if I only know the value of log(C). Be serious.
The point is that IF your data spans 5 powers of 10 in Y, then you will NEVER be happy with the result from the curve fitting toolbox, with that model in exponential for as you have it.
What will happen is the model will fit some of your data EXTREMELY well, and ignore the rest of your data.
While you CAN do the fit, no matter where you do it, the result will be pure crapola. Sorry, but it will. Your next question will be an anguished "Why does my curve fit so poorly down at the bottom end?" I really don't care if you use MATLAB, Minitab or Excel for the fit. As a power-law model as you want to fit it, you will not be happy. But hey, I've only been doing this for 40 years.

Iniciar sesión para comentar.


Sachin Bharadwaj M
Sachin Bharadwaj M el 19 de Oct. de 2021
clc; clear all;
filename = 'D:\set12.xlsx';
sheet = 1;
xRange = 'A2:E71';
yRange = 'F2:F71';
X = xlsread(filename,sheet,xRange);
Y = xlsread(filename,sheet,yRange);
modelfun = @(b,x)b(1) .* X(:,1).^b(2) .* X(:,2).^b(3)
beta0 = [0 0 0];
mdl = fitnlm(X,Y,modelfun,beta0)
Y_model = mdl.Fitted;
R_sqr = mdl.Rsquared.Ordinary;
per_dev = (Y-Y_model).*100./Y;
for i = 1:mdl.NumCoefficients
b(i,1) = mdl.Coefficients.Estimate(i,1);
end
% Y_model = b(1) .* (X(:,1).^b(2)) .* (X(:,2).^b(3)) .* ( X(:,3).^b(4))
%% PLOTTING OF RESULTS:
figure
plot(Y,Y,'k-', Y,Y+((max(Y)-0)*5/100),'g-.', Y,Y-((max(Y)-0)*5/100),'g-.', Y,Y+((max(Y)-0)*10/100),'r:', Y,Y-((max(Y)-0)*10/100),'r:');
hold on
scatter(Y, Y_model, 'b.') % ,'MarkerEdgeColor','k' , 'filled', 'MarkerFaceColor', 'b'
hold off
legend('No Error','+5%','-5%','+10%','-10%','Data points', 'Location','southeast')
xlabel('Actual', 'FontWeight', 'bold', 'FontSize', 14)
ylabel('Prediction', 'FontWeight', 'bold', 'FontSize', 14)
zlabel('T ^{o}C', 'FontWeight', 'bold', 'FontSize', 14)
title('Scatter Plot of Actual versus Fitted')

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by