MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [求助]我有一组数据如何画图 (https://www.labfans.com/bbs/showthread.php?t=7082)

xxc7902 2009-03-25 15:57

[求助]我有一组数据如何画图
 
已知x=[0.7 0.1312 0.02685 0.00943 0.0033]
y=[0.3636 0.1682 0.4741 1.2704 2.07]
拟合方程为y=ax^b
如何求a和b,求出后如何画出y=ax^b的图像

slgu 2009-03-25 16:40

回复: [求助]我有一组数据如何画图
 
x=[0.7 0.1312 0.02685 0.00943 0.0033];
y=[0.3636 0.1682 0.4741 1.2704 2.07];
fx=@(b,x)b(1)*x.^b(2);
b=rand(1,2);
b=lsqcurvefit(fx,b,x,y)
b=nlinfit(x,y,fx,b)
plot(x,y,'o','markerfacecolor','b')
x1=min(x):range(x)/80:max(x);
y1=fx(b,x1);
hold on
plot(x1,y1,'linewidth',2)

laosam280 2009-03-26 16:20

回复: [求助]我有一组数据如何画图
 
x=[0.7 0.1312 0.02685 0.00943 0.0033];
y=[0.3636 0.1682 0.4741 1.2704 2.07];
plot(x,y,'g-'); hold on
x0=[1 0]';
x=lsqnonlin('myfun',x0)
y1=y(1);
y=a*x.^b;
plot(x,y,'bo-');
%define function myfun,saved at work
function f=myfun(x,y)
x=[0.7 0.1312 0.02685 0.00943 0.0033];
y=[0.3636 0.1682 0.4741 1.2704 2.07];
y1=y(1);
z=y1-x(1)*x.^x(2);
f=z-y;

chenweibit 2009-03-26 22:17

回复: [求助]我有一组数据如何画图
 
用那个polyfit应该可以的吧,先化成log(y)=log(a)+b*log(x)求系数,详见help吧


所有时间均为北京时间。现在的时间是 14:43

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.