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 % j = jac(x); %Exakte Lösung hinterlegen diffs = zeros(19); %Speicher für Abweichungswerte initialisieren (für Darstellung) is = zeros(19); %Speicher für Iterationsnummern initialisieren (für Darstellung) for i=0:18 delta = ones(size(x,1))*10^-i; %Schrittweite vorbereiten [~, J] = numdiff(fun, x, delta); %Jacobimatrix approximieren diffs(i+1) = norm((J-j),2); %Abweichung berechnen (numerisch <-> exakt) is(i+1) = i; %Iterationsnummer speichern (für Darstellung) end %Plotten plot(is,diffs); title('Abweichung der numerischen Approximation der Jacobimatrix'); legend('Fehlerkurve') xlabel('Iterationen'); ylabel('Abweichung'); end % function diffplot