Why I cannot fit a function with more than five variables?
Mostra commenti meno recenti
Why I cannot fit a function with more than five variables?It gives the errors below, who can help me?

20 Commenti
David Goodmanson
il 6 Giu 2020
Modificato: David Goodmanson
il 8 Giu 2020
Hello zw,
given the heirerarchy of arithmetic operations in Matlab, this expression appears to be reasonable as an algebraic statement, not as the previous comment here indicated. Its applicability as a suitable model is a different question.
the cyclist
il 6 Giu 2020
Posting code is far more useful than posting an image of code, because then we could copy & paste it into a workspace to test it.
It would also be helpful if you uploaded a MAT file with your workspace variables, so we could run your exact code and data.
huazai2020
il 6 Giu 2020
Image Analyst
il 6 Giu 2020
I agree with David. Given your data, I can't see how or why your model even makes sense. Where did you come up with that model??? I don't believe any real world situation would ever need such a crazy model.
Rik
il 6 Giu 2020
But I want to do like this, I see other people do like this, how can I solve it, does there have any other functions that can do this model?
Alex Sha
il 6 Giu 2020
refer to the results below:
Root of Mean Square Error (RMSE): 0.0111861472021732
Sum of Squared Residual: 0.00212720811688768
Correlation Coef. (R): 0.928730260655716
R-Square: 0.862539897057634
Parameter Best Estimate
---------- -------------
b1 2.17150492153399E-12
b2 1.39716451311507
b3 -2.74854828910142
b4 -3.96812040839357
b5 4.23887915310233
b6 -0.0779426686949187
huazai2020
il 6 Giu 2020
huazai2020
il 6 Giu 2020
Alex Sha
il 7 Giu 2020
Hi, Wan, try a software named "1stOpt", great for curve fitting:
Function y=b1*x1^b2 *x2^b3*x3^b4*x4^b5*x5^b6;
Data;
1000 3 0.00184 0.212 0.01 0.2308
1100 3.1 0.00368 0.42401 0.02 0.28698
1200 3.2 0.00245 0.28267 0.03 0.25763
1300 3.3 0.00123 0.14134 0.04 0.20281
1400 3.4 0.00147 0.1696 0.05 0.21634
1500 3.5 0.00137 0.1575 0.06 0.21959
1600 3.6 0.00153 0.17667 0.07 0.22708
1700 3.7 0.00258 0.29777 0.08 0.23734
1800 3.8 0.0022 0.25327 0.09 0.23406
1900 3.9 0.00273 0.315 0.1 0.28892
2000 4 0.00204 0.23556 0.11 0.25137
2100 4.1 9.11E-04 0.105 0.12 0.1937
2200 4.2 0.00123 0.14133 0.13 0.2096
2300 4.3 0.00517 0.59555 0.14 0.29073
2400 4.4 0.00293 0.3377 0.15 0.2656
2500 4.5 0.00172 0.19852 0.16 0.20503
2600 4.6 0.00176 0.20262 0.17 0.22096

huazai2020
il 7 Giu 2020
Modificato: huazai2020
il 7 Giu 2020
David Goodmanson
il 7 Giu 2020
Modificato: David Goodmanson
il 8 Giu 2020
Hi zw,
It's time to look at all of the data. Past time, actually.
The following plot shows the data in log scale. As you can see, y and x4 (meaning x(:,4), similarly for the others) are almost the same. x3 is offset from x4 by an almost-constant amount on log scale, and a quick check shows that those two columns differ by a factor that is very close to being constant. So whatever effect x4 has on the fit, x3 is hardly capable of changing it. This one instance of what Image Analyst points out as highly correlated variables.
Comparing x4 to y, there are still some oscillatory kind of residuals. But since the rest of the columns of x are quite smooth, they will not be able to remove those residuals. Consequently the b exponentials for x1,x2 and x5 are pretty meaningless. Probably, when taken together as blob, they provide a slight level and slope correction to x4. But that's it.
Image Analyst
il 7 Giu 2020
I never see people do that really. Are you sure you're not thinking of a multiple linear regression where the x terms are summed instead of multiplied by each other? Is there some real world physical system you're modeling where 5 variables are mutplied by each other? If so, what is it? What do your x represent? And are you sure you're not thinking of a sum instead of a 5-way product?
huazai2020
il 8 Giu 2020
David Goodmanson
il 8 Giu 2020
Hi h2020
has your nom de plume changed?
Flags are intended to mark messages that in one way or another do not conform to the guidelines. They are not intended for follow up questions, so it woud be better if you deleted the flag and posted a comment.
Here is the code I used, after getting x and y into matrix form with x being 17x5 and y being 17x1.
n = size(x,1);
semilogy(1:n,x,1:n,y,'-o')
legend({'x1','x2','x3','x4','x5','y'})
grid on
David Goodmanson
il 8 Giu 2020
Hi h2020,
While I would not go so far as to say this can't/shouldn't be modeled, I think you should take a close look at the variables involved. Could you comment on what is the physical significance of the five columns of x, and how are they expected to relate to y? If the basic mechanism is known, is there a model that might naturally apply?
As far as x is concerned, x3 and x4 are almost the same, being almost exactly proportional to each other. So they are not really independent variables. y most closely resembles x3 in the sense that there appears to be some correlation in their variations. In terms of their shape and not their size, x1,x2 resemble each other. x5 is similar exept for a downturn on the left that does not appear to be of much help for a potential fit.
On the basis of what is going on physically, one of x1,x2,x5 might be expected to have a closer relationship to y than the others. But no matter what the mathematical form of the model is, fitting all three will probably result in one or two extra parameters that do not mean very much (as AI has mentioned).
huazai2020
il 9 Giu 2020
huazai2020
il 9 Giu 2020
Walter Roberson
il 11 Giu 2020
y=b1*x1^b2 *x2^b3*x3^b4*x4^b5*x5^b6
Take the log of both sides assuming real and non-negative x* :
log(y) = log(b1) + b2*log(x1) + b3*log(x2) + b4*log(x3) + b5*log(x4) + b6*log(x5)
So this is a linear fit in log(x*) and log(y). You can construct
nx = size(x,1);
B = [ones(nx,1), log(x)] \ log(y(:));
B(1) = exp(B(1)); %it is the only log term
B is now the closest fit in log space, suitable for using for initial coordinates for fitting in linear space.
huazai2020
il 14 Giu 2020
Walter Roberson
il 14 Giu 2020
Consider the model
log(y) = log(b1) + b2*log(x1) + b3*log(x2) + b4*log(x3) + b5*log(x4) + b6*log(x5)
but suppose you have several x* and y values. Then you can create a series of equations
log(y(1)) = log(b1)*1 + b2*log(x1(1)) + b3*log(x2(1)) + b4*log(x3(1)) + b5*log(x4(1)) + b6*log(x5(1))
log(y(2)) = log(b1)*1 + b2*log(x1(2)) + b3*log(x2(2)) + b4*log(x3(2)) + b5*log(x4(2)) + b6*log(x5(2))
log(y(3)) = log(b1)*1 + b2*log(x1(3)) + b3*log(x2(3)) + b4*log(x3(3)) + b5*log(x4(3)) + b6*log(x5(3))
...
Now arrange those in matrix form:
log(y(:)) = [1, log(x1(1)), log(x2(1)), log(x3(1)), log(x4(1)), log(x5(1)), log(x6(1));
1, log(x1(2)), log(x2(2)), log(x3(2)), log(x4(2)), log(x5(2)), log(x6(2));
1, log(x1(3)), log(x2(3)), log(x3(3)), log(x4(3)), log(x5(3)), log(x6(3));
...
] * [log(b1); b2; b3; b4; b6; b6]
where * is algebraic matrix multiplication.
This can then be written more compactly as
log(y(:)) = [Column of 1s, log(x1(:)), log(x2(:)), log(x3(:)), log(x4(:)), log(x5(:)), log(x6(:))] ...
* [log(b1); b2; b3; b4; b6; b6]
and since your x1 = x(:,1) and x2 = x(:,2) and so on, the log(x1(:)), log(x2(:)) and so on can be written more compactly as log(x), so
log(y(:)) = [Column of 1's, log(x)] * [log(b1); b2; b3; b4; b6; b6]
This is a system of linear equations. If we say
b = log(y(:))
A = [Column of 1's, log(xdata)]
X = [log(b1); b2; b3; b4; b6; b6]
then we get the familiar A*X = b .
If A were square (that is, you had 7 samples) then mathematically you would multiply the left sides by inv(A), getting
inv(A) * A * X = inv(A) * b
and inv(A) * A would be the identity matrix, and inv(A) * b could be calculated as all of those values are known, so the vector of unknowns X = inv(A) * b
You have more than 7 samples, so you do not have a square system, so you cannot use inv(), but you can do the equivalent of
pinv(A) * A * X = pinv(A) * b
to get X = pinv(A) * b as a solution that attempts to minimize error.
The MATLAB operator A\b roughly calculates pinv(A) * b, but does so using a different method of minimizing error; A\b is a least-squared error method of making that calculation.
ones(nx,1) is the "column of 1s" mentioned earlier.
Now, this all would be a least-squared calculation in log space, and would be the best fit you could get in log space for that model. But you probably want least-squared calculation in linear space, so take the result as initial values to feed into a linear least squared fit routine.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Descriptive Statistics in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


