Write an implementation of that gives the numeric approximation of a smooth function (infinitely differentiable) such as tangent(x), cosine(x), or log(x) with an adjustable level of precision in a desired programming language. Please briefly describe the method or algorithm used in your code to approximate the function. If desired, it is acceptable to not reply.
EXAMPLE.
Functionex Method Maclaurin Language ANSI C
#include <stdio.h>
double e(double e, int p)
{
double x=1,y=1; int i=1,j=1;
for(;i<p;++i) {
y*=e,j*=i;
x+=y/j;
}
return x;
}
int main()
{
double x = 1;
int p = 11;
printf("e^%f ≈ %.8f\n| Error | ≤ %f^%d/%d!\n", x, e(x,p), x, ++p, p);
}
>>4
Not machine precision, but a relative scale of accuracy. See p = 11; 11 is based on a relative scale which approches [i]e[i][sup]x[/sub] by adding x^(n)/(n)!, not how many digits or bits or something like that.
>>13
Using Monte Carlo sampling would be ever so slightly harder. The only vaguely hard part of this exercise IMO is to discover function definitions... and that's not hard with Google around.
Xarn is the only one of /proŋ/ who both uses ``faggot quotes'' and is able to make a post nitpicking about ancient language guidelines that are long obsolete and unnecessary.
Xarn bashers are like the web developers on /r/programming: nobody likes them, they shit up every thread they post in, but they're somehow convinced that they're in the majority and that the community would be worse without them.
Fuck off already.
Name:
Anonymous2010-09-23 21:59
>>14
Try the Markov Chain Monte Carlo methods. They are delicious.