0
我嘗試在GNU Octave上編寫線性&非線性迴歸,作爲我的Numerical Method類的最終項目的一部分。不過,我的代碼中有一個錯誤,這是一個簡單的解析錯誤,但我不知道如何解決它。我嘗試修正語法或嘗試改變我的編碼方式仍然卡住。需要幫助解析錯誤GNU Octave
printf("This program is use for curve fitting\n")
printf("Please enter the data in the [] by use one space to seperate each element.\n")
x = input("Enter the data(x group):")
y = input("Enter the data(y group):")
mode = input("What kind of fitting you want to do(expo((1),power(2),least-square fitting(3)):")
switch mode
case{3}
xbar = sum(x)/length(x)
ybar = sum(y)/length(y)
xy = x.*y
xs = x.^2
a1 = ((length(x)*sum(xy))-(sum(x)*sum(y)))/((sum(xs)*length(x))-(sum(x)^2))
a0 = ybar-(a1*xbar)
disp(x)
disp(y)
printf("mean of x = %d,mean of y = %d,a1 = %d.a0 = %d",xbar,ybar,a1,a0)
plot(a0+(a1*x))
case{2}
xbar = sum(x)/length(x)
ybar = sum(y)/length(y)
xy = x.*y
xs = x.^2
a1 = ((length(x)*sum(xy))-(sum(x)*sum(y)))/((sum(xs)*length(x))-(sum(x)^2))
a0 = ybar-(a1*xbar)
alpha = 10^a0
disp(x)
disp(y)
printf("mean of x = %d,mean of y = %d,a1 = %d.a0 = %d,alpha = %d,beta = %d\n",xbar,ybar,a1,a0,alpha,a0)
plot((alpha.*(x^a1))
case{1}
xbar = sum(x)/length(x)
ybar = sum(y)/length(y)
xy= x.*y
xs= x.^2
a1 = ((length(x)*sum(xy))-(sum(x)*sum(y)))/((sum(xs)*length(x))-(sum(x)^2))
a0 = ybar-(a1*xbar)
disp(x)
disp(y)
alpha = e^a1
printf("mean of x = %d,mean of y = %d,a1 = %d.a0 = %d,alpha = %d,beta = %d\n",xbar,ybar,a1,a0,alpha,a0)
plot(a0*(e^((a1*alpha).*x))
otherwise
break;
end
解析錯誤一直告訴發生錯誤的地方是{1},但我不知道錯誤是什麼。
感謝這會讓我終於完成我的項目 – RHLS