ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 08 Jan 2019 04:42:16 -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?Mon, 07 Jan 2019 07:40:18 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/Comment by Fjolfrin for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44941#post-id-44941Could you explain more about how I can use this Arb on my case? If it's not a problem, unless you want to suggest anything else not relevant to the main question, continue on the answer section, so others can find this thread more easily.
I'm a newbie on sagemath so, show mercy on the poor! ðŸ˜›ðŸ˜›Mon, 07 Jan 2019 08:10:07 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44941#post-id-44941Comment by slelievre for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44940#post-id-44940This function, if used with exact input, will keep everything exact, which might be very slow.
Floating-point will be hugely faster, with the drawback of being not certified.
The best compromise will probably be to use Arb.Mon, 07 Jan 2019 08:06:25 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44940#post-id-44940Comment by Fjolfrin for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44939#post-id-44939Yes time is imported and everything.Mon, 07 Jan 2019 08:03:05 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44939#post-id-44939Comment by Fjolfrin for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44938#post-id-44938It's indented, for some reason the indent disappeared while copying the code.Mon, 07 Jan 2019 08:01:46 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44938#post-id-44938Comment by slelievre for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44937#post-id-44937If using `time`, add `import time` as first line of the function or before the function.Mon, 07 Jan 2019 08:01:39 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44937#post-id-44937Comment by slelievre for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44936#post-id-44936Body of the `def` needs indenting.Mon, 07 Jan 2019 08:00:23 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44936#post-id-44936Comment by slelievre for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44935#post-id-44935Replacing `a = a + b` by `a += b` also increases readability.Mon, 07 Jan 2019 07:59:59 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44935#post-id-44935Comment by Fjolfrin for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44934#post-id-44934Old habits don't change ðŸ˜›ðŸ˜›
Yes I will remove them.Mon, 07 Jan 2019 07:49:54 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44934#post-id-44934Comment by slelievre for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44933#post-id-44933Side suggestion: semicolons are not needed. Removing them makes code more readable.Mon, 07 Jan 2019 07:48:03 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44933#post-id-44933Answer by tmonteil for <p>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:</p>
<pre><code>f(x) = 14 * x * exp(x-2) - 12 * exp(x-2) - 7 * x^3 + 20 * x^2 - 26 * x + 12
</code></pre>
<p>and here's the function I want to create:</p>
<pre><code>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
</code></pre>
<p>Any ideas on this? Also do you have any other suggestions on this code?</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?answer=44942#post-id-44942Here are some remarks:
First, remove any time-related lines and variables from your function. You can later time it with:
sage: %time Newton_Raphson(f, 0.2)
or even:
sage: %timeit Newton_Raphson(f, 0.2)
so that you get a race between many executions.
Then, you might want to run something like:
sage: %time Newton_Raphson(f,1)
and see that your code is lagging.
To understand what happens, let me suggest to add some debug information just after the `while` statement:
print start
As you can see, the value of the `start` real number is expressed as a huge symbolic expression involving exponentials. So you can imagine that handling such expression and testing inequalities with them is very slow (and more and more slow since the size of the expression increases a lot at each iteration).
Since you the Newton Raphson will never reach the zero of the function exactly, wht you are looking for is an approximation, so you don not care to have a long expression for such a point whose only virtue is to be close to the zero. So, yo may want a numerical approximation. For this, you can transform each of `foo`, `dfoo` and `ddfoo` as functions tranforming floating-point numbers into floating-point numbers, which you can do by using the `fast_float` function.
So just after defining `dfoo` and `ddfoo`, it suffice to add the lines:
foo = fast_float(foo)
dfoo = fast_float(dfoo)
ddfoo = fast_float(ddfoo)
Of course, you should not re-define `foo` before defining `dfoo` as Sage is not able to compute the derivative of a such numerical function, you prefer exact symbolic computations for such a computation of derivatives.
With such improvement, you can now get:
sage: %time Newton_Raphson(f,0)
CPU times: user 4 ms, sys: 0 ns, total: 4 ms
Wall time: 3.25 ms
(0.8571428346650166, 7, 0.0)
Hmm, apparently the error is zero. The reason is that in your code there is:
start = NR
error = (NR - start)
so of course the error is zero ! perhaps should you permute those two lines.Mon, 07 Jan 2019 12:32:29 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?answer=44942#post-id-44942Comment by Fjolfrin for <p>Here are some remarks:</p>
<p>First, remove any time-related lines and variables from your function. You can later time it with:</p>
<pre><code>sage: %time Newton_Raphson(f, 0.2)
</code></pre>
<p>or even:</p>
<pre><code>sage: %timeit Newton_Raphson(f, 0.2)
</code></pre>
<p>so that you get a race between many executions.</p>
<p>Then, you might want to run something like:</p>
<pre><code>sage: %time Newton_Raphson(f,1)
</code></pre>
<p>and see that your code is lagging.</p>
<p>To understand what happens, let me suggest to add some debug information just after the <code>while</code> statement:</p>
<pre><code>print start
</code></pre>
<p>As you can see, the value of the <code>start</code> real number is expressed as a huge symbolic expression involving exponentials. So you can imagine that handling such expression and testing inequalities with them is very slow (and more and more slow since the size of the expression increases a lot at each iteration).</p>
<p>Since you the Newton Raphson will never reach the zero of the function exactly, wht you are looking for is an approximation, so you don not care to have a long expression for such a point whose only virtue is to be close to the zero. So, yo may want a numerical approximation. For this, you can transform each of <code>foo</code>, <code>dfoo</code> and <code>ddfoo</code> as functions tranforming floating-point numbers into floating-point numbers, which you can do by using the <code>fast_float</code> function.</p>
<p>So just after defining <code>dfoo</code> and <code>ddfoo</code>, it suffice to add the lines:</p>
<pre><code>foo = fast_float(foo)
dfoo = fast_float(dfoo)
ddfoo = fast_float(ddfoo)
</code></pre>
<p>Of course, you should not re-define <code>foo</code> before defining <code>dfoo</code> as Sage is not able to compute the derivative of a such numerical function, you prefer exact symbolic computations for such a computation of derivatives.</p>
<p>With such improvement, you can now get:</p>
<pre><code>sage: %time Newton_Raphson(f,0)
CPU times: user 4 ms, sys: 0 ns, total: 4 ms
Wall time: 3.25 ms
(0.8571428346650166, 7, 0.0)
</code></pre>
<p>Hmm, apparently the error is zero. The reason is that in your code there is:</p>
<pre><code>start = NR
error = (NR - start)
</code></pre>
<p>so of course the error is zero ! perhaps should you permute those two lines.</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44952#post-id-44952Ok got it.
Again many thanks!Tue, 08 Jan 2019 04:42:16 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44952#post-id-44952Comment by tmonteil for <p>Here are some remarks:</p>
<p>First, remove any time-related lines and variables from your function. You can later time it with:</p>
<pre><code>sage: %time Newton_Raphson(f, 0.2)
</code></pre>
<p>or even:</p>
<pre><code>sage: %timeit Newton_Raphson(f, 0.2)
</code></pre>
<p>so that you get a race between many executions.</p>
<p>Then, you might want to run something like:</p>
<pre><code>sage: %time Newton_Raphson(f,1)
</code></pre>
<p>and see that your code is lagging.</p>
<p>To understand what happens, let me suggest to add some debug information just after the <code>while</code> statement:</p>
<pre><code>print start
</code></pre>
<p>As you can see, the value of the <code>start</code> real number is expressed as a huge symbolic expression involving exponentials. So you can imagine that handling such expression and testing inequalities with them is very slow (and more and more slow since the size of the expression increases a lot at each iteration).</p>
<p>Since you the Newton Raphson will never reach the zero of the function exactly, wht you are looking for is an approximation, so you don not care to have a long expression for such a point whose only virtue is to be close to the zero. So, yo may want a numerical approximation. For this, you can transform each of <code>foo</code>, <code>dfoo</code> and <code>ddfoo</code> as functions tranforming floating-point numbers into floating-point numbers, which you can do by using the <code>fast_float</code> function.</p>
<p>So just after defining <code>dfoo</code> and <code>ddfoo</code>, it suffice to add the lines:</p>
<pre><code>foo = fast_float(foo)
dfoo = fast_float(dfoo)
ddfoo = fast_float(ddfoo)
</code></pre>
<p>Of course, you should not re-define <code>foo</code> before defining <code>dfoo</code> as Sage is not able to compute the derivative of a such numerical function, you prefer exact symbolic computations for such a computation of derivatives.</p>
<p>With such improvement, you can now get:</p>
<pre><code>sage: %time Newton_Raphson(f,0)
CPU times: user 4 ms, sys: 0 ns, total: 4 ms
Wall time: 3.25 ms
(0.8571428346650166, 7, 0.0)
</code></pre>
<p>Hmm, apparently the error is zero. The reason is that in your code there is:</p>
<pre><code>start = NR
error = (NR - start)
</code></pre>
<p>so of course the error is zero ! perhaps should you permute those two lines.</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44951#post-id-44951`%time` is not a function, it is a "ipython magic", you can use it within the command line or a notebook.Tue, 08 Jan 2019 04:33:01 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44951#post-id-44951Comment by Fjolfrin for <p>Here are some remarks:</p>
<p>First, remove any time-related lines and variables from your function. You can later time it with:</p>
<pre><code>sage: %time Newton_Raphson(f, 0.2)
</code></pre>
<p>or even:</p>
<pre><code>sage: %timeit Newton_Raphson(f, 0.2)
</code></pre>
<p>so that you get a race between many executions.</p>
<p>Then, you might want to run something like:</p>
<pre><code>sage: %time Newton_Raphson(f,1)
</code></pre>
<p>and see that your code is lagging.</p>
<p>To understand what happens, let me suggest to add some debug information just after the <code>while</code> statement:</p>
<pre><code>print start
</code></pre>
<p>As you can see, the value of the <code>start</code> real number is expressed as a huge symbolic expression involving exponentials. So you can imagine that handling such expression and testing inequalities with them is very slow (and more and more slow since the size of the expression increases a lot at each iteration).</p>
<p>Since you the Newton Raphson will never reach the zero of the function exactly, wht you are looking for is an approximation, so you don not care to have a long expression for such a point whose only virtue is to be close to the zero. So, yo may want a numerical approximation. For this, you can transform each of <code>foo</code>, <code>dfoo</code> and <code>ddfoo</code> as functions tranforming floating-point numbers into floating-point numbers, which you can do by using the <code>fast_float</code> function.</p>
<p>So just after defining <code>dfoo</code> and <code>ddfoo</code>, it suffice to add the lines:</p>
<pre><code>foo = fast_float(foo)
dfoo = fast_float(dfoo)
ddfoo = fast_float(ddfoo)
</code></pre>
<p>Of course, you should not re-define <code>foo</code> before defining <code>dfoo</code> as Sage is not able to compute the derivative of a such numerical function, you prefer exact symbolic computations for such a computation of derivatives.</p>
<p>With such improvement, you can now get:</p>
<pre><code>sage: %time Newton_Raphson(f,0)
CPU times: user 4 ms, sys: 0 ns, total: 4 ms
Wall time: 3.25 ms
(0.8571428346650166, 7, 0.0)
</code></pre>
<p>Hmm, apparently the error is zero. The reason is that in your code there is:</p>
<pre><code>start = NR
error = (NR - start)
</code></pre>
<p>so of course the error is zero ! perhaps should you permute those two lines.</p>
http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44950#post-id-44950Thanks a lot! I have the exact same results. After I fixed the error thing I also get a logical result on this scope too:
0
(0.8571428346650166, 7, 9.64919707358014e-05)
Just to clarify, because I can't get the "%time" function you mentioned, what is the syntax of it? I tried to even copy an example from Sage's documentation, however I can't seem to get it to work. I have the "time" library imported.
Meaning what I type exactly to get it to work? This is what I get for typing this: `%time Newton_Raphson(f, 0)`
Error in lines 48-48
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute flags=compile_flags) in namespace, locals
File "", line 1, in <module
File "/cocalc/lib/pyTue, 08 Jan 2019 04:06:01 -0600http://ask.sagemath.org/question/44932/generic-symbolic-function-as-input-in-actual-funciton/?comment=44950#post-id-44950