ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 07 Jan 2019 07:40:18 -0600Generic Symbolic function as input in actual funcitonhttp://ask.sagemath.org/question/44932/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?FjolfrinMon, 07 Jan 2019 07:40:18 -0600http://ask.sagemath.org/question/44932/