⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jacobi.m

📁 The following Matlab code converts a Matrix into it a diagonal and off-diagonal component and perfor
💻 M
字号:
%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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -