|
From: Petr M. <mi...@ph...> - 2014-10-30 14:13:06
|
>> 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?
newton.gp:
f(x) = cos(x)
steps=0; x=0.5; eps=1e-6
call "newton_inside.gp"
print steps, x
newton_inside.gp:
x = x - eps*f(x)/( f(x+eps) - f(x) )
steps = steps + 1
if (abs(f(x)) < 1e-10 ) exit
call "newton_inside.gp"
Should we remove if and call? :-)
I really like the current loops. They help with easy tasks a lot.
> 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.
Gnuplot is mainly for plotting, and "for" helps a lot!
---
Petr
|