【发布时间】:2019-01-20 14:02:43
【问题描述】:
我正在尝试对 Julia 中的非线性方程组进行数值求解。我正在使用牛顿法。我唯一不知道该怎么做,就是计算雅可比矩阵。到目前为止,我找不到计算偏导数的函数。
我的系统:
f(x1, x2) = 2*x2^2+x1^2
g(x1, x2) = (x1-1)^2 + (x2-1/2)^2
感谢您的支持, 最好的祝福, 西蒙。
【问题讨论】:
标签: julia
我正在尝试对 Julia 中的非线性方程组进行数值求解。我正在使用牛顿法。我唯一不知道该怎么做,就是计算雅可比矩阵。到目前为止,我找不到计算偏导数的函数。
我的系统:
f(x1, x2) = 2*x2^2+x1^2
g(x1, x2) = (x1-1)^2 + (x2-1/2)^2
感谢您的支持, 最好的祝福, 西蒙。
【问题讨论】:
标签: julia
让我写一下我在 cmets 中已经提到的答案。您可以使用自动微分来计算偏导数:
julia> using ForwardDiff
julia> f(x) = 2*x[2]^2+x[1]^2 # f must take a vector as input
f (generic function with 2 methods)
julia> g = x -> ForwardDiff.gradient(f, x); # g is now a function representing the gradient of f
julia> g([1,2]) # evaluate the partial derivatives (gradient) at some point x
2-element Array{Int64,1}:
2
8
【讨论】: