Arithmetic Mathematical Functions - Printable Version +- Forums - Open Redstone Engineers (https://forum.openredstone.org) +-- Forum: Off-Topic (https://forum.openredstone.org/forum-4.html) +--- Forum: Off-Topic Discussion (https://forum.openredstone.org/forum-5.html) +--- Thread: Arithmetic Mathematical Functions (/thread-51.html) |
Arithmetic Mathematical Functions - fibonatic - 04-19-2013 I have occasionally been messing with arithmetical calculations to perform mathematical functions using Boolean logic (redstone). Addition, subtraction, multiplication and division are relative simple. You could of course use Taylor series to proximate any function, since it only requires multiplication and addition, however you would have to add more and more terms to get a sufficiently accurate answer when trying to calculate the solution further away from the point where you proximate the function. After this I also explored if the iterative Newton–Raphson method would be a possibility. However often these solution require other not easy to calculate functions and the amount of iterations isn't fixed, since you would continue until <x_n+1 = x_n>. But there are also other methods of acquiring solutions of certain function, often using conditional logic. For instance to calculate the square root, this method can also be applied to binary which has the advantage that you do not have to calculate the z, since it would either be an one or a zero (in which case the remainder after the subtraction will be negative). After I discovered this method to calculate the square root I also wondered if there are also methods for other commonly using mathematical functions like logarithm, exponential, sine, cosine and tangent. And I came up with this arithmetic to calculate log2(x): Code: y = floor(log2(x(n))); // Exponent The exponential function would be easier to do, since it would just be <N> multiplications. I am not sure how you could do sine, cosine and tangent. However you would only have to be able to do one of them, since: cos(x) = sin(x + pi/2) and tan(x) = sin(x) / sin(x + pi/2). First of all you could just take the 2*pi module of x, since all these functions are cyclic, which reduces the range of x in which the solution has to be found. This range can be reduced even more, since: sin(x) = -sin(x + pi) and half a cycle is symmetric as well: sin(x) = sin(pi - x), which reduces the range of x down to [0, pi/2]. RE: Arithmetic Mathematical Functions - Nickster258 - 04-19-2013 Nice... RE: Arithmetic Mathematical Functions - Xray_Doc - 09-10-2013 > black pink shoes |