需要帮助解析错误GNU Octave

时间:2015-04-24 14:35:59

标签: linux octave

我尝试写线性& GNU Octave上的非线性回归作为我在Numerical Method类的最终项目的一部分。我的代码中仍有一个错误,这是一个简单的解析错误,但我不知道如何解决它。我尝试修复语法或尝试改变我的编码仍然卡住的方式。

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},但我不知道错误是什么。

1 个答案:

答案 0 :(得分:1)

该案例标签前面的行括号不匹配:

plot((alpha.*(x^a1))