Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Expand
titlekvadratrot.m
Code Block
titlekvadratrot.m
function retur = kvadratrot(tall)
    x = 1;
    er_over_feilgrense = true;
    i = 1;
    N = 4;
    retur = zeros(1, N);
    retur(1) = x;
    while er_over_feilgrense
       ny_x = x + (tall - x^2)/(2*x);
       relativ_endring = abs(ny_x - x)/x;
       er_over_feilgrense = relativ_endring >= 1e-9;
       x = ny_x;
       i = i + 1;
       if i > N
           N = 2*N;
           retur(N) = 0;
       end
       retur(i) = x;
    end
    retur = retur(1:i);
end 

Videoforklaring (mm17:ss) 02) 

Del 1 (6:04)Del 2 (10:58)
Widget Connector
urlhttps://www.youtube.com/watch?v=CWZtCGKaVrc
Widget Connector
urlhttps://www.youtube.com/watch?v=lBZZmUUXu0w
Introduksjon og forklaring av oppgaven, og start på løsningsfunksjon (ingen plotting).Matlab-kode for å konstruere figuren.


Løsningsforslag

Expand
titleHvis du har prøvd selv, trykk her for å se svaret...
Code Block
titleplott_kvadratrotestimat.m
function plott_kvadratrotestimat(tall)
    estimat = kvadratrot(tall);
    n = length(estimat) - 1;
    plot([0, n], [tall, tall], 0:n, estimat);
    y_max_1 = tall;
    y_max_2 = max(estimat);
    y_max = max(y_max_1, y_max_2);
    axis([0, n, 0, 1.1*y_max]);
end