function fout = foutperc(A, Ak) % given matrix A and its approximation Ak % determine percentage error in function values % difference in A - Ak in percentage is given [m, n] = size(A); B = A - Ak; % ik heb de loops in elkaar geschoven, vanwege leesbaarheid en % snelheid magA = 0.0; magB = 0.0; for i=1:m for j=1:n magA = magA + abs(A(i,j)); magB = magB + abs(B(i,j)); end end magA = magA / (m * n); magB = magB / (m * n); fout = magB * 100 / magA;