Numerical integration in a function

i like this post (click again to cancel)
1
i dont like this post (click again to cancel)
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.

asked Sep 01 '10

willmwade gravatar image willmwade
47 3 5 8

2 Answers:

i like this answer (click again to cancel)
4
i dont like this answer (click again to cancel) willmwade has selected this answer as correct

This 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
link

posted Sep 01 '10

burcin gravatar image burcin
1068 10 32
http://erocal.org/burcin
This worked great! willmwade (Sep 01 '10)
Great! 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. kcrisman (Sep 01 '10)
i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

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

link

posted Sep 01 '10

kcrisman gravatar image kcrisman
6784 14 67 152
Please 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. burcin (Sep 01 '10)
Maybe 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? niles (Sep 01 '10)
The 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. willmwade (Sep 01 '10)
For 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? willmwade (Sep 01 '10)
The 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. willmwade (Sep 01 '10)
see 2 more comments

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Tags:

Stats:

Asked: Sep 01 '10

Seen: 920 times

Last updated: Sep 01 '10

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.