r语言求系数最小二乘估计y=ax+bx+c y=ax^n

Python022

r语言求系数最小二乘估计y=ax+bx+c y=ax^n,第1张

y=ax+bx+c

程序:a=lm(dist~speed+I(speed^2),data=cars)

y=ax^n

先将试子两边取对数得lny=lna+n*lnx,变成Y=A+N*X

程序:

x=log(cars[,1])

y=log(cars[,2])

a=lm(x~y)

static void(int[]group)

{

int temp

int pos=0

for(int i=0i<group.Length-1i++)

{

pos=i

for(intj=i+1j<group.Lengthj++)

{

if(group[j]<group[pos])

{

pos=j

}

}//第i个数与最小的数group[pos]交换

temp=group[i]

group[i]=group[pos]

group[pos]=temp

}

}