Julia中的偏导数

Julia中的偏导数,julia,Julia,我试图用数值方法解朱莉娅的一个非线性方程组。我用的是纽顿方法。我唯一不知道怎么做的就是计算雅可比矩阵。到目前为止,我找不到计算偏导数的函数 我的系统: f(x1, x2) = 2*x2^2+x1^2 g(x1, x2) = (x1-1)^2 + (x2-1/2)^2 谢谢你的支持, 顺致敬意, Szymon.让我写下我在评论中提到的答案。您可以使用自动微分来计算偏导数: julia> using ForwardDiff julia> f(x) = 2*x[2]^2+x[1]^2

我试图用数值方法解朱莉娅的一个非线性方程组。我用的是纽顿方法。我唯一不知道怎么做的就是计算雅可比矩阵。到目前为止,我找不到计算偏导数的函数

我的系统:

f(x1, x2) = 2*x2^2+x1^2
g(x1, x2) = (x1-1)^2 + (x2-1/2)^2
谢谢你的支持, 顺致敬意,
Szymon.

让我写下我在评论中提到的答案。您可以使用自动微分来计算偏导数:

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

让我写下我在评论中已经提到的内容作为回答。您可以使用自动微分来计算偏导数:

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

我想你可以用你可以在这里找到一些例子我想你可以用你可以在这里找到一些例子