>
x<-c(6.19,2.51,7.29,7.01,5.7,2.66,3.98,2.5,9.1,4.2)
>
y<-c(5.25,2.83,6.41,6.71,5.1,4.23,5.05,1.98,10.5,6.3)
> lsfit(x,y)
$coefficients
Intercept
0.8310557 0.9004584
输出结果:
> plot(x,y)
> x<-c(1,2,3,4,5,6)
> y<-c(9,18,31,48,69,94)
> lsfit(x,y)
$coefficients
Intercept
-14.66667
def func(p,x):
p0=[10,10,10]
#读取结果
a,b,c=Para[0]
print("a=",a,"b=",b,"c=",c)
print("cost:" str(Para[1]))
print("求解的拟合直线为:")
print("y=" str(round(a,2)) "x*x " str(round(b,2)) "x "
str(c))
a= 2.0 b= 3.0 c= 4.0
cost:2
求解的拟合直线为:
y=2.0x*x 3.0x 4.0