Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Julia 非线性解算器总是产生零残差_Julia - Fatal编程技术网

Julia 非线性解算器总是产生零残差

Julia 非线性解算器总是产生零残差,julia,Julia,我正在学习如何求解非线性方程组和Julia(1.3.1),并想问我们应该如何使用NLsolve 作为第一步,我尝试以下方法: using NLsolve uni = 1 z = 3 x = [3,2,4,5,6] y = z .+ x print(y) function g!(F, x) F[1:uni+4] = y .- z - x end nlsolve(g!, [0.5,0.9,1,2,3]) 我确认其工作原理如下: Results of Nonlinear Solver Alg

我正在学习如何求解非线性方程组和Julia(1.3.1),并想问我们应该如何使用NLsolve

作为第一步,我尝试以下方法:

using NLsolve
uni = 1
z = 3
x = [3,2,4,5,6]
y = z .+ x
print(y)
function g!(F, x)
    F[1:uni+4] = y .- z - x
end
nlsolve(g!, [0.5,0.9,1,2,3])
我确认其工作原理如下:

Results of Nonlinear Solver Algorithm
 * Algorithm: Trust-region with dogleg and autoscaling
 * Starting Point: [0.5, 0.9, 1.0, 2.0, 3.0]
 * Zero: [2.999999999996542, 2.000000000003876, 4.000000000008193, 4.999999999990685, 5.999999999990221]
 * Inf-norm of residuals: 0.000000
 * Iterations: 2
 * Convergence: true
   * |x - x'| < 0.0e+00: false
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 3
 * Jacobian Calls (df/dx): 3
这段代码产生了一个奇怪的结果,如下所示

Results of Nonlinear Solver Algorithm
 * Algorithm: Trust-region with dogleg and autoscaling
 * Starting Point: [0.5, 0.6]
 * Zero: [0.5, 0.6]
 * Inf-norm of residuals: 0.000000
 * Iterations: 0
 * Convergence: true
   * |x - x'| < 0.0e+00: false
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 1
 * Jacobian Calls (df/dx): 1
非线性求解器算法的结果 *算法:带狗腿和自动缩放的信赖域 *起点:[0.5,0.6] *零:[0.5,0.6] *残差的Inf范数:0.000000 *迭代次数:0 *收敛性:正确 *| x-x'|<0.0e+00:错误 *| f(x)|<1.0e-08:正确 *函数调用(f):1 *雅可比调用(df/dx):1
因此,从本质上讲,函数总是得到0作为返回值,因此初始输入总是成为解。我无法理解为什么这不起作用,以及为什么它的行为与第一个示例不同。我能听听你的建议吗?

你需要将
Res
更新到位。现在你知道了

Res = ones(S+S)

它对输入
Res
进行阴影处理。直接更新
Res

谢谢您的评论。你的意思是我必须摆脱它吗?然后,我得到另一个错误<代码>边界错误:尝试访问索引[3:4]处的2元素数组{Float64,1}您说您有两个未知数(因为输入x0的长度为2),但随后尝试给出4个残差(4个方程)。这真的是你想要的吗?是的,所以它被高估了。我们不能做这样的分析吗?NLsolve.jl解F(x)=0。你想找到什么
x
以使
|F(x)|
最小化?请看Optim.jl,谢谢!我会查一查。
Res = ones(S+S)