function retur = kvadratrot(tall)
x = 1;
er_over_feilgrense = true;
i = 1;
while er_over_feilgrense
ny_x = x + (tall - x^2)/(2*x);
fprintf('Iterasjon #%d: x_%d = %.10f, x_%d = %.10f\n', i, i-1, x, i, ny_x);
relativ_endring = abs(ny_x - x)/x;
er_over_feilgrense = relativ_endring >= 1e-9;
x = ny_x;
i = i + 1;
end
retur = x;
end |