Fitting powerlaw between two points

6 vues (au cours des 30 derniers jours)
Faisal le 16 Mai 2023
Commenté : Faisal le 21 Mai 2023
I have a set of data in x and y in excel scheet. The x and y makes a parabolic like curve, on the same graph I want to draw a power law between two points indicated by x1 and y1 (in excel sheet). As an example I have shown a picture that I did in excel but I need it in Matlab.
Thank you

Réponse acceptée

John D'Errico
John D'Errico le 16 Mai 2023
Given two points exactly, thus:
yx = [0.047 100;
0.0382 0.1933];
y1 = yx(:,1);
x1 = yx(:,2);
You want the power law curve that passes exactly through the two points?
Effectively, you have the model curve:
x = a*y^b
With two points, and two unknown parameters, there is exactly one such curve that passes through the pair of points.
You can extract the coefficients using nothing more complicated than polyfit. That is, suppose we log the model? That gives us:
log(x) = log(a) + b*log(y)
As such, the parameters are given as:
P1 = polyfit(log(y1),log(x1),1)
P1 = 1×2
30.1414 96.7658
a = exp(P1(2))
a = 1.0589e+42
b = P1(1)
b = 30.1414
PLotting the two points, and the curve between them, we see:
hold on
fplot(@(y) a*y.^b,[0,0.047])
  3 commentaires
Faisal le 21 Mai 2023
Thank you @John D'Errico again for explaining it in details.
yes that makes sense. A true parabola can only be obtained near the origin.
I really appreciate your help. Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Get Started with Curve Fitting Toolbox 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