fitting data with power function

7 vues (au cours des 30 derniers jours)
Jana
Jana le 26 Juin 2011
Hi,
I need to curve fit to data, which i had meassured. I must use method of least squares and for fitting i must use a „power function“ y= a*x^b ((ftype=fittype('power1')); I need to find the coefficients a and b. But i dont know how to do in Matlab, i try to write some m-scripts but it doesnt works.
Example of meassured data:
X=[-90; -80; -70; -60; -50; -40; -30; -20; -10;0; 10; 20; 30; 40; 50;60; 70; 80; 90]
Y=[-2.8691; -2.4261; -2.0042; -1.7497; -1.3936; -1.1392; -0.9356; -0.7321; -0.5286; 0; 0.3872; 0.6416; 0.8451; 1.0995; 1.3031; 1.6083;1.9136; 2.3207; 2.524]
I will be grateful for any idea or any help. Thank you very much.
  1 commentaire
safak
safak le 8 Avr 2018
did you check the command window, coefficients may be printed out there

Connectez-vous pour commenter.

Réponses (3)

bym
bym le 26 Juin 2011
Plotting your data it does not seem to fit a power function and seems linear. You can use the backslash operator to do least squares
doc mldivide
or in the plot window, use tools>basic fitting to fit a linear equation
  4 commentaires
Jana
Jana le 27 Juin 2011
But i cannot use logarithmus, because i have a zero defined in my data, i try to use a logaritmus, but it doesnt work for zero, do you know how to write a script using logaritmus,and backslash for data with zero?
bym
bym le 27 Juin 2011
if you have zeros in your data, then maybe a different approach is warranted. If you can post some 'real' data then maybe a solution can be found

Connectez-vous pour commenter.


Jana
Jana le 28 Juin 2011
Modifié(e) : Walter Roberson le 8 Avr 2018
Data : X=[-90; -80; -70; -60; -50; -40; -30; -20; -10;0; 10; 20; 30; 40; 50;60; 70; 80; 90]
Y=[-2.8691; -2.4261; -2.0042; -1.7497; -1.3936; -1.1392; -0.9356; -0.7321; -0.5286; 0; 0.3872; 0.6416; 0.8451; 1.0995; 1.3031; 1.6083;1.9136; 2.3207; 2.524]
other measurement:
x= =[-90; -80; -70; -60; -50; -40; -30; -20; -10;0; 10; 20; 30; 40; 50;60; 70; 80; 90]
y=[-2.8182 -2.6147 -2.4621 -2.1059 -1.8515 -1.6481 -1.2409 -0.9865 -0.7831 -0.0707 0.5398 0.8961 1.1504 1.4048 1.6083 1.9136 2.117 2.3206 2.5751]]
value -.0707 is something like offset, it must be deducted from all other data in y.
other measurement:
X=[-90; -80; -70; -60; -50; -40; -30; -20; -10;0; 10; 20; 30; 40; 50;60; 70; 80; 90]
Y= [-3.5306 -3.2762 -3.0218 -2.6656 -2.3604 -2.0042 -1.5462 -1.1392 -0.7831 -0.0707 0.7434 1.0995 1.6084 2.0663 2.5242 2.9821 3.2874 3.5418 3.9488]
value -0,0707 is ofsfset too, and it must be dedicated from other values in y.
i use this algoritm, but its ignore zero, so its wrong way !
close all
clear all
clc
x=[-90; -80; -70; -60; -50; -40; -30; -20; -10; 10; 20; 30; 40; 50;60; 70; 80; 90]';
y=[-2.8691; -2.4261; -2.0042; -1.7497; -1.3936; -1.1392; -0.9356; -0.7321; -0.5286; 0.3872; 0.6416; 0.8451; 1.0995; 1.3031; 1.6083;1.9136; 2.3207; 2.524]';
plot(x,y,'r-*')
lnx = log(abs(x));
lny = log(abs(y));
A = [lnx;ones(size(x))];
v = inv(A*A')*A*lny';
a = v(1);
b = exp(v(2));
hold on
u = 0:1:100;
plot(u,b*u.^a);
u = -100:1:0;
plot(u,-b*(-u).^a);
hold off
a
b
legend('namerena data', 'prolozeni dat',2)

Matt Fig
Matt Fig le 28 Juin 2011
If I use this data and plot as you show, it looks near linear. Why would you think this should be a power law relation?
x=[-90; -80; -70; -60; -50; -40; -30; -20; -10; 10; 20; 30; 40; 50;60; 70; 80; 90]';
y=[-2.8691; -2.4261; -2.0042; -1.7497; -1.3936; -1.1392; -0.9356; -0.7321; -0.5286; 0.3872; 0.6416; 0.8451; 1.0995; 1.3031; 1.6083;1.9136; 2.3207; 2.524]';
plot(x,y,'r-*')
pp = polyfit(x,y,1); % Fit a line to the data
yp = polyval(pp,x);
hold on
plot(x,yp,'b') % Plot the line in blue.
  1 commentaire
Jana
Jana le 30 Juin 2011
I need to compare coefficients,how can I have a coefficients from polyfit and polyval?
Because the comparison is the result of my thesis..

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by