Zitat von "Philipp K. Janert" <ja...@ie...>:
> f(x) = cos(x)
> steps=0; x=0.5; eps=1e-6
>
> while( abs(f(x)) > 1e-10 ) {
> x = x - eps*f(x)/( f(x+eps) - f(x) )
> steps = steps + 1
> }
>
> print steps, x
g(x) = cos(x)
h(x) = (abs(g(x)) < 1e-10) ? x : h(x - eps*g(x)/(g(x + eps) - g(x)))
x=0.5; eps=1e-6
print h(x)
Should we now remove recursion?
Don't get me wrong, I really appreciate, that you raised this discussion.
Only, in my opinion you cannot completely sort out "programming features".
Yes, the loops allow you to do some kind of programming, but it also allows
you to greatly improve your gnuplot scripts when working e.g. with many data
files:
files = system('ls *.dat')
plot for [f in files] f
That makes your script much more flexible, e.g. when dealing with a lot of
similar measurement sets which then basically requires only a single script
for plotting.
Christoph
|