需要帮助解析错误 GNU Octave
Need help parse error GNU Octave
我尝试在 GNU Octave 上编写线性和非线性回归,作为我数值方法 class 期末项目的一部分。我的代码中仍然有一个错误,这是一个简单的解析错误,但我不知道如何修复它。我尝试修复语法或尝试更改我的编码方式仍然卡住了。
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
Parse error 一直提示错误发生的地方是case{1} 但我不知道是什么错误。
案例标签前一行的括号不匹配:
plot((alpha.*(x^a1))
我尝试在 GNU Octave 上编写线性和非线性回归,作为我数值方法 class 期末项目的一部分。我的代码中仍然有一个错误,这是一个简单的解析错误,但我不知道如何修复它。我尝试修复语法或尝试更改我的编码方式仍然卡住了。
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
Parse error 一直提示错误发生的地方是case{1} 但我不知道是什么错误。
案例标签前一行的括号不匹配:
plot((alpha.*(x^a1))