小型 Octave 程序中的索引越界错误

Index out of Bounds error in a small Octave program

这是代码,它只是根据两个输入 x 和 y 计算两个输出。

function [nextX, nextY]=newton(x,y)
nextX= x-((6*(x^2)*(y^2)*(x+y)-9*(y^2)((y^3)+14)-2*(x^2)*(5*(x^2)-69))/(x*y*(18*x*y+20)));
nextY= y-((10*(x^4)+18*x^2*(y^3)-414*(x^2)+30*x*(y^2)-420*x)/(x*y*(18*x*y+20)));
end   

[x,y]=newton(1,1)

我明白了

error: newton: A(I): index out of bounds; value 15 out of bound 1
error: called from:
error:   newton at line 2, column 6

每当我尝试 运行 它时,我都是八度的新手,我真的看不出我做错了什么。

你的代码中有一个非常简单的错误(可能是拼写错误):

nextX= x-((6*(x^2)*(y^2)*(x+y)-9*(y^2)((y^3)+14)-2*(x^2)*(5*(x^2)-69))/(x*y*(18*x*y+20)));
                                      ^

两个括号之间没有运算符,因此 Octave 假设您正试图通过它的索引获取 vector/matrix 的元素,因此抛出 index out of bounds 异常。

可能您想将两个值相乘:

nextX= x-((6*(x^2)*(y^2)*(x+y)-9*(y^2)*((y^3)+14)-2*(x^2)*(5*(x^2)-69))/(x*y*(18*x*y+20)));