[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 760 KB, 1024x768, Penguins.jpg [View same] [iqdb] [saucenao] [google]
5160579 No.5160579 [Reply] [Original]

rate this algorithm to find arctg

function arctg(t, dtheta)
{ for (theta=0; tan(theta) < t; theta += dtheta) ;
return theta;
}

>> No.5160615

>>5160579
Pretty poor, you have O(1/dtheta) computations of tan(theta) for a O(dtheta) relative precision, and relative precision is useless near -1 and 1 because you'd want a relative precision of the distance to -1 (or 1). For instance, if arctan(t) = 1 - 10^(-100), then you will need dtheta around 10^(-100) to have a good idea of arctan(t), and the program will terminate in 10^100 steps. If you take a smaller precision, you will only know that arctan(t) is close to 1, but not how close to 1 it is. The least you could do if you want to use this kind of algorithm is make the precision parameter decay exponentially as you get closer to -1 or 1.

>> No.5160661

>>5160615

This.

>> No.5160666

Bad.
Learn about series expansion.