Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- scale=$1;
- echo ${scale:="20"} >> /dev/null;
- echo "number to raise:";read y;
- echo "numerator of exponent:";read n;
- echo "denominator of exponent:";read d;
- x=1;prev=0; #//x = guess;prev = loop control testing;
- for((z=0;z<50;)) do
- x=$(echo "scale=$scale;$x*(1-1/$d)+$y/$d/$x^($d - 1)"|bc); #//see newton method for finding the Nth root of a number.
- if [[ "$x" == "$prev" ]]; then z=555; fi;
- prev=$x;
- if [[ $(echo $2|head -c 2) == "-d" ]]; then echo $prev; fi;
- done;
- echo;echo -n "$y^($n/$d)="; echo "$x^$n"|bc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement