39 lines
989 B
Matlab
39 lines
989 B
Matlab
function diffplot(fun, jac, x)
|
|
%
|
|
%
|
|
% [f, J] = diffplot(fun, jac, x) plots difference between symbolic
|
|
% differentiation and approximation by finite differences
|
|
%
|
|
% INPUT
|
|
% fun function handle; fun: R^n -> R^n
|
|
% jac function handle; jac: R^n -> R^(mxn)
|
|
% x point x in R^n to evaluate f and jacobian
|
|
%
|
|
|
|
% testrahmen
|
|
min = 0;
|
|
max = 18;
|
|
len = max-min+1;
|
|
|
|
% initialisierungen
|
|
indices = zeros(len,1);
|
|
values = zeros(len,1);
|
|
|
|
for i=min:max
|
|
% speichert i für die darstellung im graphen
|
|
indices(i-min+1)=i;
|
|
% schrittweitenvektor 10^-i berechnen
|
|
delta = 10^(-i) * ones(size(x,1));
|
|
% numerische ableitung berechnen
|
|
[~,df] = numdiff(fun,x,delta);
|
|
% genormte differenz speichern
|
|
values(i-min+1) = abs(df-jac(x));
|
|
end
|
|
|
|
% ausgabe
|
|
plot(indices,values);
|
|
xlabel('i (Mit delta = 10^-i)');
|
|
ylabel('Differenz');
|
|
|
|
end % function diffplot
|