Fitting powerlaw between two points
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hi,
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

0 commentaires
Réponse acceptée
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)
a = exp(P1(2))
b = P1(1)
PLotting the two points, and the curve between them, we see:
plot(y1,x1,'bo')
hold on
fplot(@(y) a*y.^b,[0,0.047])
3 commentaires
Plus de réponses (0)
Voir également
Catégories
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!