2 ms·
If anyone wants to do the thing romwell describes without an avalanche of math, try this one-liner: bash$ gnuplot -e 'set format x "%.15f"; set format y "%
by jart 6y ago
If anyone wants to do the thing romwell describes without an avalanche of math, try this one-liner:
bash$ gnuplot -e 'set format x "%.15f"; set format y "%.15f"; set samples 100000; set table "cos.dat"; set xrange [-3*pi/8:3*pi/8]; plot cos(x); f(x) = a + b*x**2 + c*x**4; fit f(x) "cos.dat" using 1:2 via a,b,c'
It then gives you "optimized" values for a/b/c from your template formula, thus resulting in
cos(x) ~= 0.999923 + -.498826*x*x + .0391071*x*x*x*x
Which is even more accurate but only to about four decimal places.