set fit errorvariables
set key left top
#set title "Graf závislosti prodloužení pružiny na jejím zatížení"
set xlabel "\varphi"
set ylabel "N"

A = 351
B = 4770
C = 180
K = 4595
S = 6
L = 180
f(x) = - A * abs(x - C) + B
g(x) = K * exp(-(x-L)*(x-L)/(2*S*S))
fit f(x) 'treti.dat' using 1:4 via A,B,C
fit g(x) 'treti.dat' using 1:4 via K,S,L
plot 'treti.dat' using 1:4:5 with yerrorbars lt 1 title 'Naměřené hodnoty', f(x) lt 1 title 'Trojúhelník', g(x) lt 3 title 'Gauss'

set terminal latex
set out "graftreti.tex"
replot
set out
set term win

set print "fittreti.txt"
print "   f(x) = -A* abs(x-C) + B"
print "   g(x) = K * exp(-(x-L)*(x-L)/(2*S*S))"
print A, " +/- ", A_err, ",   rel. chyba ", abs(A_err/A*100), " %"
print B, " +/- ", B_err, ",   rel. chyba ", abs(B_err/B*100), " %"
print C, " +/- ", C_err, ",   rel. chyba ", abs(C_err/C*100), " %"
print K, " +/- ", K_err, ",   rel. chyba ", abs(K_err/K*100), " %"
print L, " +/- ", L_err, ",   rel. chyba ", abs(L_err/L*100), " %"
print S, " +/- ", S_err, ",   rel. chyba ", abs(S_err/S*100), " %"
set print

