fitting data with power function
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
bym
2011-6-26
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 个评论
bym
2011-6-27
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
Matt Fig
2011-6-28
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!