Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Generic Symbolic function as input in actual funciton

So I have this assignment for university, and I'm trying to write a generic Newton's method which will take any symbolic function as input. I just don't know how to declare this on the function's inputs. Here's the function I want as input:

f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12

and here's the function I want to create:

def Newton_Raphson(foo, start):
dfoo = diff(foo)
ddfoo = diff(dfoo)
t0 = time.time()
while foo(start) * ddfoo(start) <= 0:
    start = start + 10^-6
NR = start - foo(start) / dfoo(start);
noNR = 1;
while abs(foo(NR)) > 10^-6:
    NR = start - foo(start)/dfoo(start);
    start = NR;
    error = (NR - start);
    noNR = noNR + 1;
t1 = time.time()
tNR = t1 - t0
return NR, noNR, error, tNR

Any ideas on this? Also do you have any other suggestions on this code?

Generic Symbolic function as input in actual funciton

So I have this assignment for university, and I'm trying to write a generic Newton's method which will take any symbolic function as input. I just don't know how to declare this on the function's inputs. Here's the function I want as input:

f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12

and here's the function I want to create:

def Newton_Raphson(foo, start):
 dfoo = diff(foo)
 ddfoo = diff(dfoo)
 t0 = time.time()
 while foo(start) * ddfoo(start) <= 0:
     start = start + 10^-6
 NR = start - foo(start) / dfoo(start);
 noNR = 1;
 while abs(foo(NR)) > 10^-6:
     NR = start - foo(start)/dfoo(start);
     start = NR;
     error = (NR - start);
     noNR = noNR + 1;
 t1 = time.time()
 tNR = t1 - t0
 return NR, noNR, error, tNR

Any ideas on this? Also do you have any other suggestions on this code?

Generic Symbolic function as input in actual funciton

So I have this assignment for university, and I'm trying to write a generic Newton's method which will take any symbolic function as input. I just don't know how to declare this on the function's inputs. Here's the function I want as input:

f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12

and here's the function I want to create:

def Newton_Raphson(foo, start):
    dfoo = diff(foo)
    ddfoo = diff(dfoo)
    t0 = time.time()

    while foo(start) * ddfoo(start) <= 0:
        start = start + += 10^-6

    NR = start - foo(start) / dfoo(start);
    noNR = 1;

    while abs(foo(NR)) > 10^-6:
        NR = start - foo(start)/dfoo(start);
        start = NR;
        error = (NR - start);
        noNR = noNR + += 1;

    t1 = time.time()
    tNR = t1 - t0
    return NR, noNR, error, tNR

Any ideas on this? Also do you have any other suggestions on this code?

Generic Symbolic function as input in actual funciton

So I have this assignment for university, and I'm trying to write a generic Newton's method which will take any symbolic function as input. I just don't know how to declare this on the function's inputs. Here's the function I want as input:

f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12

and here's the function I want to create:

def Newton_Raphson(foo, start):
    dfoo = diff(foo)
    ddfoo = diff(dfoo)
    t0 = time.time()

    while foo(start) * ddfoo(start) <= 0:
        start += 10^-6

    NR = start - foo(start) / dfoo(start);
dfoo(start)
    noNR = 1;
1

    while abs(foo(NR)) > 10^-6:
        NR = start - foo(start)/dfoo(start);
        start = NR;
foo(start)/dfoo(start)
        start = NR
        error = (NR - start);
start)
        noNR += 1;
1

    t1 = time.time()
    tNR = t1 - t0
    return NR, noNR, error, tNR

Any ideas on this? Also do you have any other suggestions on this code?

Generic Symbolic function as input in actual funciton

So I have this assignment for university, and I'm trying to write a generic Newton's method which will take any symbolic function as input. I just don't know how to declare this on the function's inputs. Here's the function I want as input:

f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12

and here's the function I want to create:

def Newton_Raphson(foo, start):
    dfoo = diff(foo)
    ddfoo = diff(dfoo)
    t0 = time.time()

    while foo(start) * ddfoo(start) <= 0:
        start += 10^-6

    NR = start - foo(start) / dfoo(start)
    noNR = 1

    while abs(foo(NR)) > 10^-6:
        NR = start - foo(start)/dfoo(start)
        start = NR
        error = (NR - start)
        noNR += 1

    t1 = time.time()
    tNR = t1 - t0
    return NR, noNR, error, tNR

Any ideas on this? Also do you have any other suggestions on this code?