ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 01 Sep 2010 14:28:06 +0200Numerical integration in a functionhttps://ask.sagemath.org/question/7660/numerical-integration-in-a-function/ f(x,y)=numerical_integral(1/d*2*x*y,.01,Infinity)[0]
Error
So what I want is to the integration wait until after the variables have been substituted so that it is able to numerically integrate. (Yes I need to numerically integrate. This is a simplified form that reproduces the same result.)
f(3,1)=numerical_integral(1/d*2*3*1,.01,Infinity)[0]
406.69135669845798
I thought there might be a way using a lambda defined function, but I was unable to find one.Wed, 01 Sep 2010 09:20:26 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/Answer by burcin for <pre><code>f(x,y)=numerical_integral(1/d*2*x*y,.01,Infinity)[0]
Error
</code></pre>
<p>So what I want is to the integration wait until after the variables have been substituted so that it is able to numerically integrate. (Yes I need to numerically integrate. This is a simplified form that reproduces the same result.)</p>
<pre><code>f(3,1)=numerical_integral(1/d*2*3*1,.01,Infinity)[0]
406.69135669845798
</code></pre>
<p>I thought there might be a way using a lambda defined function, but I was unable to find one.</p>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?answer=11602#post-id-11602This works for me:
sage: var('d')
d
sage: f = lambda x,y: numerical_integral(1/d*2*x*y,.01,Infinity)[0]
sage: f(3,1)
406.69135669845832
Wed, 01 Sep 2010 11:35:01 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?answer=11602#post-id-11602Comment by kcrisman for <p>This works for me:</p>
<pre><code>sage: var('d')
d
sage: f = lambda x,y: numerical_integral(1/d*2*x*y,.01,Infinity)[0]
sage: f(3,1)
406.69135669845832
</code></pre>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22745#post-id-22745Great! However, you won't be able to take the derivative of this function, as far as I know. Maybe our f(x,y) should make a lambda function when it's not possible to make a symbolic function... but that sounds hard.Wed, 01 Sep 2010 14:28:06 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22745#post-id-22745Comment by willmwade for <p>This works for me:</p>
<pre><code>sage: var('d')
d
sage: f = lambda x,y: numerical_integral(1/d*2*x*y,.01,Infinity)[0]
sage: f(3,1)
406.69135669845832
</code></pre>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22754#post-id-22754This worked great!Wed, 01 Sep 2010 12:32:51 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22754#post-id-22754Answer by kcrisman for <pre><code>f(x,y)=numerical_integral(1/d*2*x*y,.01,Infinity)[0]
Error
</code></pre>
<p>So what I want is to the integration wait until after the variables have been substituted so that it is able to numerically integrate. (Yes I need to numerically integrate. This is a simplified form that reproduces the same result.)</p>
<pre><code>f(3,1)=numerical_integral(1/d*2*3*1,.01,Infinity)[0]
406.69135669845798
</code></pre>
<p>I thought there might be a way using a lambda defined function, but I was unable to find one.</p>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?answer=11601#post-id-11601This isn't really an answer, but ...
This is one of many things about the integration interface that needs to be improved. We have two fundamentally different syntaxes for symbolic versus numerical integration. Would you find it possible to collate all your ask.sagemath.org questions about this into one collection and open a Trac ticket for "Improve numerical integration syntax" or something like that? I don't think it would be terribly difficult to fix many of these things, but it's much harder because the requests (and possibly tickets - over the last few years) are sort of scattered. Wed, 01 Sep 2010 09:54:20 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?answer=11601#post-id-11601Comment by kcrisman for <p>This isn't really an answer, but ...</p>
<p>This is one of many things about the integration interface that needs to be improved. We have two fundamentally different syntaxes for symbolic versus numerical integration. Would you find it possible to collate all your <a href="http://ask.sagemath.org">ask.sagemath.org</a> questions about this into one collection and open a Trac ticket for "Improve numerical integration syntax" or something like that? I don't think it would be terribly difficult to fix many of these things, but it's much harder because the requests (and possibly tickets - over the last few years) are sort of scattered. </p>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22746#post-id-22746I was referring to both the uniformity issue and the fact that users should need to use lambda functions as little as possible. I totally appreciate Burcin's comment, though :)Wed, 01 Sep 2010 14:26:38 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22746#post-id-22746Comment by burcin for <p>This isn't really an answer, but ...</p>
<p>This is one of many things about the integration interface that needs to be improved. We have two fundamentally different syntaxes for symbolic versus numerical integration. Would you find it possible to collate all your <a href="http://ask.sagemath.org">ask.sagemath.org</a> questions about this into one collection and open a Trac ticket for "Improve numerical integration syntax" or something like that? I don't think it would be terribly difficult to fix many of these things, but it's much harder because the requests (and possibly tickets - over the last few years) are sort of scattered. </p>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22750#post-id-22750Here is a [tutorial on functional programming][1] written by Minh.
[1]: http://www.sagemath.org/doc/thematic_tutorials/functional_programming.html#define-small-functions-using-lambdaWed, 01 Sep 2010 12:41:21 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22750#post-id-22750Comment by willmwade for <p>This isn't really an answer, but ...</p>
<p>This is one of many things about the integration interface that needs to be improved. We have two fundamentally different syntaxes for symbolic versus numerical integration. Would you find it possible to collate all your <a href="http://ask.sagemath.org">ask.sagemath.org</a> questions about this into one collection and open a Trac ticket for "Improve numerical integration syntax" or something like that? I don't think it would be terribly difficult to fix many of these things, but it's much harder because the requests (and possibly tickets - over the last few years) are sort of scattered. </p>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22751#post-id-22751The only other item would be a mess I keep running into at defining the variable of integration. integral(f(x),x,0,1) verses numerical_integral(f(x),0,1). Numerical integral errors when the variable of integration is declared. If it would not do that, it would help bring the two into uniformity.Wed, 01 Sep 2010 12:39:45 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22751#post-id-22751Comment by willmwade for <p>This isn't really an answer, but ...</p>
<p>This is one of many things about the integration interface that needs to be improved. We have two fundamentally different syntaxes for symbolic versus numerical integration. Would you find it possible to collate all your <a href="http://ask.sagemath.org">ask.sagemath.org</a> questions about this into one collection and open a Trac ticket for "Improve numerical integration syntax" or something like that? I don't think it would be terribly difficult to fix many of these things, but it's much harder because the requests (and possibly tickets - over the last few years) are sort of scattered. </p>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22752#post-id-22752For example in the answer to this one. I did not know that f=lambda x: x^2 would allow me to do f(2) result 4. Nor has any of the python docs on it been the most help. Mind I do more in Java :( and PHP :) than the little I have done in Python, but still some Sage documentation pointing at others?Wed, 01 Sep 2010 12:36:57 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22752#post-id-22752Comment by burcin for <p>This isn't really an answer, but ...</p>
<p>This is one of many things about the integration interface that needs to be improved. We have two fundamentally different syntaxes for symbolic versus numerical integration. Would you find it possible to collate all your <a href="http://ask.sagemath.org">ask.sagemath.org</a> questions about this into one collection and open a Trac ticket for "Improve numerical integration syntax" or something like that? I don't think it would be terribly difficult to fix many of these things, but it's much harder because the requests (and possibly tickets - over the last few years) are sort of scattered. </p>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22757#post-id-22757Please have a concrete suggestion for the syntax before opening the ticket. Tickets without specific goals tend to be ignored by the developers, and are generally hard to resolve. The sage-devel list is the right place for a discussion on how the improved syntax might be.Wed, 01 Sep 2010 11:46:23 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22757#post-id-22757Comment by niles for <p>This isn't really an answer, but ...</p>
<p>This is one of many things about the integration interface that needs to be improved. We have two fundamentally different syntaxes for symbolic versus numerical integration. Would you find it possible to collate all your <a href="http://ask.sagemath.org">ask.sagemath.org</a> questions about this into one collection and open a Trac ticket for "Improve numerical integration syntax" or something like that? I don't think it would be terribly difficult to fix many of these things, but it's much harder because the requests (and possibly tickets - over the last few years) are sort of scattered. </p>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22756#post-id-22756Maybe what's also (or alternatively) needed is a ticket for "improve documentation for numerical and symbolic integration", since these questions seem (to me) to get resolved, but not always in obvious ways. @willmwade: could you identify the things you've learned which are not documented?Wed, 01 Sep 2010 11:46:28 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22756#post-id-22756Comment by willmwade for <p>This isn't really an answer, but ...</p>
<p>This is one of many things about the integration interface that needs to be improved. We have two fundamentally different syntaxes for symbolic versus numerical integration. Would you find it possible to collate all your <a href="http://ask.sagemath.org">ask.sagemath.org</a> questions about this into one collection and open a Trac ticket for "Improve numerical integration syntax" or something like that? I don't think it would be terribly difficult to fix many of these things, but it's much harder because the requests (and possibly tickets - over the last few years) are sort of scattered. </p>
https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22753#post-id-22753The main area I think that could use some documentation is the use of the Python inline lambda function. Most if not all of the integration issues I have had, have been solved with using this. However there is little in how to use it with Sage specifically.Wed, 01 Sep 2010 12:34:38 +0200https://ask.sagemath.org/question/7660/numerical-integration-in-a-function/?comment=22753#post-id-22753