fitting with custom equation
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi I am havng troble in fitting the data with costoum eqaution: I/y = x/a + (1-x)/b. with and b are the fitting parametrs. x and y values are as given below.
y = [1.6E5 2.5E5 4.1E5 8E5 1E6 2E6 7E6 2E7]
x = [17 20 27 59 62 81 89 95]
Thank you in advance for your support!
0 commentaires
Réponses (2)
John D'Errico
le 12 Oct 2024
(I assume you intended to write 1/y, and not I/y, where the variable I is not defined.)
y = [1.6E5 2.5E5 4.1E5 8E5 1E6 2E6 7E6 2E7];
x = [17 20 27 59 62 81 89 95];
Often it is the case, when you cannot fit a model to your data, it means you model does not have the correct shape. This model would be a nice STRAIGHT line, when we plot it as as 1/y versus x.
If we plot 1/y versus x, we would expect to see that behavior in the data. And here, it looks like we have not at all a straight line.
plot(x,1./y,'o')
I might also point out that since your data is scaled to go from 0-100 in x, so the model you wanted to write was probably
I/y = x/a + (100-x)/b.
How can we estimate a and b in that model? Easily enough. We could even use polyfit. There is no need to use a custom model in fit. But you can. Next, note that I'll fit the model as
1/y = x*a + (100-x)*b
and then invert a and b. fit manages to make it converge better if I do so.
mdl = fittype('x*a + (100 - x)*b','indep','x')
fittedmdl = fit(x(:),1./y(:),mdl,'start',[0.001 0.001]) % note that fit wants COLUMN vectors of data.
plot(fittedmdl,x,1./y)
a = 1./fittedmdl.a
b = 1./fittedmdl.b
Again though, I don't think your model fits the data very well.
0 commentaires
Star Strider
le 12 Oct 2024
This is probably as good as you can hope for —
% I/y = x/a + (1-x)/b
y = [1.6E5 2.5E5 4.1E5 8E5 1E6 2E6 7E6 2E7];
x = [17 20 27 59 62 81 89 95];
figure
plot(x, y)
grid
figure
plot(x, 1./y)
grid
objfcn = @(b,x) x./b(1) + (1 - x)./b(2);
opts = optimset('MaxFunEvals',1E6);
[B,rn] = fminsearch(@(b) norm(1./y - objfcn(b,x)), randn(2,1)+1E10, opts)
figure
plot(x, 1./y, 'pb', 'MarkerSize',12, 'MarkerFaceColor','b', 'DisplayName','Data')
hold on
plot(x, objfcn(B,x), '-r', 'LineWidth',2, 'DisplayName','Regression')
hold off
grid
xlabel('$x$', 'Interpreter','LaTeX', 'FontSize',12)
ylabel('$\frac{1}{y}$', 'Interpreter','LaTeX', 'FontSize',12)
legend('Location','best')
text(35, 5E-6, sprintf('$\\frac{1}{y} = \\frac{x}{%13.5E} + \\frac{1-x}{%13.5E}$',B), 'Interpreter','LaTeX', 'FontSize',14)
.
1 commentaire
Alex Sha
le 22 Jan 2025
First of all, the fitting function could be rewritten from "1/y = x*a + (100-x)*b" to "y = 1/(x*a + (100-x)*b)", the results will then be good enough.
Sum Squared Error (SSE): 3179655964395.29
Root of Mean Square Error (RMSE): 630441.904975717
Correlation Coef. (R): 0.99637702865579
R-Square: 0.992767183232941
Parameter Best Estimate
--------- -------------
a 519856.258368166
b 514524.404512105

Voir également
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!