Who can help me fit the data using the matlab, thank you.

1 view (last 30 days)
Who can help me fit the data using the matlab, thank you.The fitting equation should be below:
y=b1*x1^b2 *x2^b3*x3^b4*x4^b5*x5^b6*x6^b7
  2 Comments
huazai2020
huazai2020 on 5 Aug 2020
These the data are just some part data from the whole data, the questions can be avoided if I put all the data, could you show me the code if I want to fit like this equation, thank you.

Sign in to comment.

Answers (1)

Ayush Gupta
Ayush Gupta on 4 Sep 2020
Please refer to the following code on how to go about it and get the individual coefficients b1, b2, etc.
[D,S,R] = xlsread('data.xlsx');
x1 = D(:,1);
x2 = D(:,2);
x3 = D(:,3);
x4 = D(:,4);
x5 = D(:,5);
x6 = D(:,6);
z = D(:,7);
x = [x1(:) x2(:) x3(:) x4(:) x5(:) x6(:)];
coeff = [ones(numel(z),1),log(x)]\log(z);
coeff (1) = exp(Coeff (1));
Please read about use '\'
  4 Comments
Walter Roberson
Walter Roberson on 7 Sep 2020
x = [x1(:) x2(:) x3(:) x4(:) x5(:) x6(:)];
Creates columns in an array, x. The first column is taken from x1, the second column is taken from x2, and so on.
coeff = [ones(numel(z),1),log(x)]\log(z);
The first part, ones(numel(z),1), creates a column of ones that is as long as z is (which in turn should be the same as the length of each of the x* variables.) So the left side of the \ creates an array in which the first column is all ones and the remaining columns are the logs of the x* variables.
The right side, log(z) is what it looks like, the log of the z variables.
The \ between the two asks for least squared fitting.
When you ask for least-squared fitting, then a column of ones corresponds to the constant term . The expression is finding the best values, coeff, such that
coeffs(1) + coeffs(2)*log(x1) + coeffs(3) + log(x2) + coeffs(4) * log(x3) + coeffs(5) * log(x4) + coeffs(6) * log(x5) + coeffs(7) * log(x6) fits log(z)
If you were to take exp() of this, it would be like
exp(coeffs(1)) * x1^coeffs(2) * x2^coeffs(3) * x3^coeffs(4) * x4^coeffs(5) * x5^coeffs(6) * x6^coeffs(7) fits z
and then
coeff (1) = exp(Coeff (1));
is converting the coeffs(1) that you got from the fitting to the exp(coeffs(1)) that you can see in the latter expression.

Sign in to comment.

Categories

Find more on Numeric Types in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!