Metode Numerik: Metode Tabel

Berikut adalah implementasi metode tabel untuk mencari akar kuadrat dari 645

clc
format long;

target = 645;

tbl_start = 25;
tbl_end = 26;

while true 
    step = (tbl_end - tbl_start)/10;
    % y = x^2
    disp('-------------------------');
    disp('|  i    |        i^2    |');
    disp('-------------------------');
    nearest_answer = tbl_start;
    for i=tbl_start:step:tbl_end
        disp(sprintf('|%7.3f|%15.7f|', i, i^2));
        if i^2 < target
            nearest_answer = i;
        end
    end

    nearest_answer
    new_tbl_end = nearest_answer + step

    tbl_start = nearest_answer;
    tbl_end = new_tbl_end;

    pause(1);
end

 

Leave a Reply