program ChybaMetody; var x:real; h:real; soubor:Text; jmenoSouboru:string[255]; skutecnaDerivace,odhadDerivace1,odhadDerivace2,odhadDerivace5:real; function f(x:real):real; (* funkce *) begin f:=sin(x); end; function df(x:real):real; (* derivace funkce *) begin df:=cos(x); end; function num1_df(x,h:real):real; (* odhad derivace metodou prvniho radu *) begin num1_df:=(f(x+h)-f(x))/h; end; function num2_df(x,h:real):real; (* odhad derivace metodou druheho radu *) begin num2_df:=(f(x+h/2)-f(x-h/2))/h; end; function num5_df(x,h:real):real; (* odhad derivace metodou pateho radu *) begin num5_df:=1/(12*h)*(f(x-2*h)-8*f(x-h)+8*f(x+h)-f(x+2*h)); end; begin write('Zadej x: '); readln(x); write('Zadej h: '); readln(h); write('Zadej jmeno vystupniho souboru: '); readln(jmenoSouboru); assign(soubor,jmenoSouboru); (* propojime promennou soubor k fyzickemu souboru *) rewrite(soubor); (* otevreme soubor pro zapis *) while h>1e-15 do begin skutecnaDerivace := df(x); odhadDerivace1 := num1_df(x,h); odhadDerivace2 := num2_df(x,h); odhadDerivace5 := num5_df(x,h); write(soubor,h); (* na radek zapiseme h *) write(soubor,' '); write(soubor,skutecnaDerivace); (* na radek zapiseme skutecnou derivaci *) write(soubor,' '); write(soubor,odhadDerivace1); (* na radek zapiseme odhad metodou prvniho radu *) write(soubor,' '); write(soubor,(odhadDerivace1-skutecnaDerivace)/skutecnaDerivace); (* relativni chyba odhadu metodou prvniho radu *) write(soubor,' '); write(soubor,odhadDerivace2); (* na radek zapiseme odhad metodou druheho radu *) write(soubor,' '); write(soubor,(odhadDerivace2-skutecnaDerivace)/skutecnaDerivace); (* relativni chyba odhadu metodou druheho radu *) write(soubor,odhadDerivace5); (* na radek zapiseme odhad metodou pateho radu *) write(soubor,' '); write(soubor,(odhadDerivace5-skutecnaDerivace)/skutecnaDerivace); (* relativni chyba odhadu metodou pateho radu *) writeln(soubor); (* odradkujeme *) h := h/1.1; (* zmensime h *); end; close(soubor) (* uzavreme soubor *) end.