[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: The old divergences thread (for DT)



PureBytes Links

Trading Reference Links

Herman,
We may have another approach through while() statement.
[For the simplicity, the //next decimals are in a loop form ]

//Sqrt(X) approximation
X=2;Precision=7;
a=1;b=2;
st0=0.1;//the initial step
z=0;
//1st decimal
i=a;
while(i^2<X)
{
z=i;
i=i+st0;
}
//next decimals
for(n=1;n<Precision;n++)
{
st0=0.1*st0;
i=z;
while(i^2<x)
{
z=i;
i=i+st0;
}
}
Title="Sqrt("+WriteVal(X,1.0)+")="+WriteVal(z,1+0.1*n);

When we have the Sqrt(2)=1.41, the next loop will search 1.411, 
1.412, 1.413, 1.414, 1.415 and will stop there, since 1.415 gives 
false output.
In this way, the 3rd loop needs 5 steps instead of 10. Since decimals 
will be equally disributed below and above 5 [I hope you dont always 
search an 1.99999 !!] we gain many steps.
Without this, one should begin from 1 and search every 0.00001 up to 
1.41421.
This is done by the full code

//Sqrt(X) full approximation
X=2;Precision=5;
a=1;b=2;
st0=10^(-Precision);//the initial step
z=0;
//decimals
i=a;
while(i^2<X)
{
z=i;
i=i+st0;
}
Title="Sqrt("+WriteVal(X,1.0)+")="+WriteVal(z,1+0.1*Precision);

and it is not the best choice !!

A simple criterion to see the difference, is your endless loop 
detection threshold. 
If it is set, for example, to 100000 iterations, the first method 
will permit Precision=7 whereas the 2nd[full] method will not go more 
than Precision=5.

The steps of the 1st method depend on the result : You will not be 
that lucky with Sqrt(3.56). It is 1.886796, all the decimal digits 
are >5 and the steps per digit will be 9+9+7+8+10+7 respectively !!
It is much better to search Sqrt(2.2811), it is 1.510331 and will 
take 6+2+1+4+4+2 steps per digit.
You may also put a small counter to count the total steps of the 
approximation, it is interesting.
Dimitris Tsokakis

 


--- In amibroker@xxxxxxxxxxxxxxx, "Herman vandenBergen" <psytek@xxxx> 
wrote:
> Thank you DT, as usual your reply is not only informative but 
entertaining
> :-) an 8x improvement in speed would be just fine. If my own 
solution is
> general I will post it.
> 
> I think I received enough ideas to try a few things, solving a small
> challenge with your owninput is half the fun and a better way to 
learn.
> 
> Thanks everybody and have a great day!
> herman
>   -----Original Message-----
>   From: DIMITRIS TSOKAKIS [mailto:TSOKAKIS@x...]
>   Sent: January 29, 2004 2:16 AM
>   To: amibroker@xxxxxxxxxxxxxxx
>   Subject: [amibroker] Re: Successive Approximation in afl
> 
> 
>   Herman,
>   my method is a bit different.
>   I begin with the 1st digit accuracy [10 steps maximum, 1.0 to 1.9]
>   and localize
>   1.4<sqrt(2)<1.5
>   Then, for the 2nd digit, 10 steps [maximum] again to obtain
>   1.41<sqrt(2)<1.42
>   and so on.
>   In the average, I need 5 steps per digit and, for a 3-decimal
>   accuracy it will take about
>   5*5*5=125 steps instead of the normal 1000.
>   Archimedes, the copyright of the method, was not working with
>   decimals.
>   For some reason [not explained anywhere],  his first choice was 
the
>   sevenths of the unity 1/7, 2/7, 3/7 etc .
>   So, in his famous "Measurement of a Circle", he proves that
>   3+1/7>pi>3+10/71
>   As you see, he slightly increases the denominator [he does not
>   increase the numerator].
>   There are some obscure statements, he never explained, for 
example,
>   how did he came to the [useful approximation]
>   265/153<sqrt(3)<1351/780 [!!!].
>   but, we can not always have what we want...
>   Dimitris Tsokakis
>   --- In amibroker@xxxxxxxxxxxxxxx, "Herman vandenBergen" 
<psytek@xxxx>
>   wrote:
>   > thanks DT, I have to study your code but I think you have the
>   general idea.
>   > I have an impossible formula to transform (it contains HHV and 
LLVs,
>   > stochastic mutation) and want to find the x that would give me 
the
>   given y.
>   > Right now I linearly increment x untill I hit my y-target,  
this is
>   awfully
>   > slow.
>   >
>   > like y = function(x); // y ranges 0-100 and I want 2 decimal 
places
>   for x
>   > that gives me a given y
>   >
>   > I thought cutting the range in half, see whether it is greater 
or
>   less, cut
>   > the result in half again, etc. I am not a math guy but I have 
used
>   > AD-converters that worked like that and what we can do in 
hardware
>   we can do
>   > in software :-)
>   >
>   > thanks for the starter DT,
>   > herman
>   >
>   >
>   >
>   >
>   >  -----Original Message-----
>   > From: DIMITRIS TSOKAKIS [mailto:TSOKAKIS@x...]
>   > Sent: January 28, 2004 9:18 PM
>   > To: amibroker@xxxxxxxxxxxxxxx
>   > Subject: [amibroker] Re: Successive Approximation in afl
>   >
>   >
>   >   Herman,
>   >   You mean a procedure like this
>   >
>   >   a=1;b=2;z=0;
>   >   st0=0.1;st1=0.01;st2=0.01;
>   >   //1st decimal
>   >   for(i=a;i<b;i=i+st0)
>   >   {
>   >   if(i^2<2 AND (i+st0)^2>2)
>   >   z=i;
>   >   }
>   >   //2nd decimal
>   >   for(i=z;i<z+st0;i=i+st1)
>   >   {
>   >   if(i^2<2 AND (i+st1)^2>2)
>   >   z=i;
>   >   }
>   >   //...etc
>   >   Plot(z,"sqrt(2)",1,1);
>   >
>   >   to find sqrt(2) without using all the values from 1 to 2 ?
>   >   Dimitris Tsokakis
>   >   --- In amibroker@xxxxxxxxxxxxxxx, "Herman vandenBergen"
>   <psytek@xxxx>
>   >   wrote:
>   >   > Hello,
>   >   >
>   >   > has anybody come accross a successive approximation routine 
in
>   afl?
>   >   Or
>   >   > perhaps js?
>   >   >
>   >   > thanks,
>   >   > herman
>   >
>   >
>   >
>   >   Send BUG REPORTS to bugs@xxxx
>   >   Send SUGGESTIONS to suggest@xxxx
>   >   -----------------------------------------
>   >   Post AmiQuote-related messages ONLY to: 
amiquote@xxxxxxxxxxxxxxx
>   >   (Web page: http://groups.yahoo.com/group/amiquote/messages/)
>   >   --------------------------------------------
>   >   Check group FAQ at:
>   > http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>   >
>   >
>   >
>   > ----------------------------------------------------------------
----
>   --------
>   > --
>   >   Yahoo! Groups Links
>   >
>   >     a.. To visit your group on the web, go to:
>   >     http://groups.yahoo.com/group/amibroker/
>   >
>   >     b.. To unsubscribe from this group, send an email to:
>   >     amibroker-unsubscribe@xxxxxxxxxxxxxxx
>   >
>   >     c.. Your use of Yahoo! Groups is subject to the Yahoo! 
Terms of
>   Service.
> 
> 
> 
>   Send BUG REPORTS to bugs@xxxx
>   Send SUGGESTIONS to suggest@xxxx
>   -----------------------------------------
>   Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
>   (Web page: http://groups.yahoo.com/group/amiquote/messages/)
>   --------------------------------------------
>   Check group FAQ at:
> http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> 
> 
> 
> --------------------------------------------------------------------
--------
> --
>   Yahoo! Groups Links
> 
>     a.. To visit your group on the web, go to:
>     http://groups.yahoo.com/group/amibroker/
> 
>     b.. To unsubscribe from this group, send an email to:
>     amibroker-unsubscribe@xxxxxxxxxxxxxxx
> 
>     c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of 
Service.


Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/amibroker/

To unsubscribe from this group, send an email to:
 amibroker-unsubscribe@xxxxxxxxxxxxxxx

Your use of Yahoo! Groups is subject to:
 http://docs.yahoo.com/info/terms/