script to iterate

Hi

i need to find x in the following equation such that it satisfies this condition:

y/x-ln(x)-1.24=0

how can i write a script to iterate to give random x to satisfy this equation.
y is different each time too. any help with awk/shell script will be awesome!

thanks

something along the lines of:

(rewriting your equation to isolate an iteration:

x=y/ln(3.455613x)
)

#  y=1;x=1;for i in {1..100}; do x=$(calc "$y/(log(3.455613*$x))"); echo $x;done
0.806452
0.975715
.
<snip>
.
0.890054
0.890054

where I have calc as a function:

#  typeset -f calc
calc ()
{
    nawk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'
}

In this case, then:

#  calc "log(0.890054)"+1.24
1.123527

#  calc 1/0.890054
1.123527

You may prefer to define an epsilon value and check the diff between successive iterations to define your accuracy.

HTH

1 Like