jacobi.m
来自「The following Matlab code converts a Mat」· M 代码 · 共 21 行
M
21 行
%1.3 Subroutine jacobi
function dfdx = jacobi(func,x,h,varargin)
% jacobi: calculates the jacobian of the system of equations
% defined by the function "func". This code uses a second order
% accurate method to evaluate the derivative
% input:
% x = the value at which the jacobian is calculated
% h = the step size used in the estimation of the derivative
% intermediate variables:
% I = identity matirx
% n = size of the vector x
if nargin <3, h = 1e-3*norm(x); end
h2 = 2*h; n = length(x);
x = x(:)'; % ensures that x is a row vector
I = eye(n);
for i=1:n
dfdx(:,i) = (feval(func,x+I(i,:)*h,varargin{:})-...
feval(func,x-I(i,:)*h,varargin{:}))'/h2;
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?