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

[amibroker] Is foreign bar empty?



PureBytes Links

Trading Reference Links

Herman,
Here is a more elegant form:
Repeat the same part
//next digit
...
to increase the accuracy of the result.

//Sqrt(2) approximation
 a=1;b=2;
st0=0.1;//the initial step
z=0;
n=0;//the precision counter
//1st decimal
for(i=a;i<b;i=i+st0)
{
if(i^2<2 AND (i+st0)^2>2)
{z=i;}
}
n=n+1;

//next decimal
a=z;b=a+st0;st0=0.1*st0;n=n+1;
for(i=a;i<b;i=i+st0)
{
if(i^2<2 AND (i+st0)^2>2)
{z=i;}
}

//next decimal
a=z;b=a+st0;st0=0.1*st0;n=n+1;
for(i=a;i<b;i=i+st0)
{
if(i^2<2 AND (i+st0)^2>2)
{z=i;}
}

//next decimal
a=z;b=a+st0;st0=0.1*st0;n=n+1;
for(i=a;i<b;i=i+st0)
{
if(i^2<2 AND (i+st0)^2>2)
{z=i;}
}

//next decimal
a=z;b=a+st0;st0=0.1*st0;n=n+1;
for(i=a;i<b;i=i+st0)
{
if(i^2<2 AND (i+st0)^2>2)
{z=i;}
}

//next decimal
a=z;b=a+st0;st0=0.1*st0;n=n+1;
for(i=a;i<b;i=i+st0)
{
if(i^2<2 AND (i+st0)^2>2)
{z=i;}
}

Title="Sqrt(2)="+WriteVal(z,1+(n/10))+"\n["+WriteVal(n,1.0)+" digits 
precision]";

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 Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

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/