📄 fxstiff.m
字号:
function dfdx = fxstiff (t,x,f)
%----------------------------------------------------------------------
% Usage: dfdx = fxstiff (t,x,f)
%
% Description: Estimate the Jacobian matrix J = df(t,x)/dx numerically
% using central differences. Return the result in the
% n by n matrix dfdx.
%
% Inputs: t = time
% x = n by 1 state vector
% f = string containing name of function whose
% derivatives are to be estimated.
%
% Outputs: dfdx = n by n Jacobian matrix containing derivatives,
% dfdt(k,j) = df(k)/dx(j).
%----------------------------------------------------------------------
chkvec (x,2,'fxstiff');
chkfun (feval(f,t,x),3,'fxstiff');
n = length(x);
x0 = zeros (n,1);
x1 = zeros (n,1);
x2 = zeros (n,1);
d = eps^(1/3);
x0 = x;
for j = 1 : n
x0(j) = x(j) + d;
x1 = feval(f,t,x0);
x0(j) = x(j) - d;
x2 = feval(f,t,x0);
x0(j) = x(j);
for i = 1 : n
dfdx(i,j) = (x1(i) - x2(i))/(2*d);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -