Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

«Exercise» Numeric Est. of Smooth Functions

Name: Anonymous 2010-09-23 7:50

/prog/ Exercise

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.

XAMPLE.

Function ex
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);
}

Name: Anonymous 2010-09-23 7:52

Less of this.

Name: Anonymous 2010-09-23 7:58

lambda x:x

Name: Anonymous 2010-09-23 8:16

adjustable level of precision
double
Oh God IHBT.

Name: Anonymous 2010-09-23 8:33

>>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.

Name: Anonymous 2010-09-23 10:48

Fuck your shit.

Name: Anonymous 2010-09-23 10:56

>>5
You have a bug in your BBCode.

Name: Anonymous 2010-09-23 11:32

>>7
Someone should fix it.

Name: Anonymous 2010-09-23 12:11

>>5
``Precision'' and ``accuracy'' are two different things.

Name: Anonymous 2010-09-23 12:28

>>9
you sure like to make claims without proving them, xarn

Name: Anonymous 2010-09-23 12:30

>>5,9
Sounds like I could Monte Carlo something and it would meet the precision requirement while being wildly inaccurate.

Name: Anonymous 2010-09-23 12:47

>>8
I can fix it but you'll have to give me svn write access to your post repository.

Name: Anonymous 2010-09-23 13:07

>>11
Go for it.

Just make sure you are challenging yourself and not undermining your own potential by doing something easy.

Name: Anonymous 2010-09-23 13:25

>>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.

Also: http://rosettacode.org/wiki/Monte_Carlo_methods

Name: Anonymous 2010-09-23 13:47

>>10
That's the second time I've been accused of being Xarn this week.

But it's true, look it up.

Name: Anonymous 2010-09-23 13:49

>>15
Hotaru likes to pretend everyone who disagrees with him is Xarn. Just take it as a compliment.

Name: Anonymous 2010-09-23 14:32

>>16
Xarn likes to pretend everyone who disagrees with him is Hotaru.

Name: Anonymous 2010-09-23 14:36

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.

Name: Anonymous 2010-09-23 14:52

>>18
>>9,15 here
I use ``faggot quotes'' jokingly. And yes, I love being a pedantic asshole.

Name: Anonymous 2010-09-23 15:54

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: Anonymous 2010-09-23 21:59

>>14
Try the Markov Chain Monte Carlo methods.  They are delicious.

Also ignore >>15-20.

Name: Anonymous 2010-09-23 22:06

Do i win?


Function ex
Method Maclaurin
Language ANSI C

#include <stdio.h>
double e(double e, int p)
{
    double x=1,y=1; int i=1,j=1;
   
    loop:
    y*=e,j*=i;
    x+=y/j;
    ++i;
    if(i<p)
        goto loop;
       
    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);
}

Name: Anonymous 2010-09-24 3:24

Has anyone listened to Xarn's voice before?

Name: Anonymous 2010-09-24 5:04

Here's my entry:

def e(e, p):
    x = j = 1
    y = 1.
    for i in xrange(1, p):
        y *= e
        j *= i
        x += y / j
    return x

x = 1
p = 11
print "e^%f ≈ %.8f\n| Error | ≤ %f^%d/%d!\n" % (x, e(x, p), x, p + 1, p + 1)


Original work.

Name: Anonymous 2010-09-24 6:16

fact = product . enumFromTo 1

Name: Anonymous 2010-09-24 6:38

-- optimized
fact = product . enumFromTo 2

Name: Anonymous 2010-09-24 6:48

>>25
smooth function (infinitely differentiable)

Name: Anonymous 2010-09-24 7:09

Name: Anonymous 2010-09-24 7:36


ackermann 0 = 0
ackermann 1 = 1
ackermann n = ackermann (n-1) + ackermann (n-2)

Name: Anonymous 2010-09-24 12:44

>>29
Writing fibs with your dog, aren't you?

Name: Anonymous 2010-09-27 1:00

Name: Anonymous 2010-09-27 1:04

fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

Name: Anonymous 2010-09-27 16:50

>>32
This makes me wonder. Would the HASKAL compiler produce similar code compilé?

Name: Anonymous 2010-11-25 4:41

Don't change these.
Name: Email:
Entire Thread Thread List