# Revision history [back]

When you input f(x,a) into numerical_integral, it already knows that a is a parameter. The optional input params is a way for you to give the value of the parameters.

sage: var('x a')
sage: f(x,a)=a*x
sage: numerical_integral(f(x,a),0,1, params=[6])
(2.9999999999999996, 3.330669073875469e-14)


I'm not sure exactly what happens when you evaluate

sage: numerical_integral(f(x,a),0,1, params=[a])
(0.3333333333333333, 3.700743415417188e-15)


--- it would seem that the parameter disappears (or is given the value 1). This means your g(x,a) defined as

sage: g(x,a)=numerical_integral(f(x,a),0,1, params=[a])


doesn't depend on a, so g(x,anything) will always get you the same value.

For some reason, it doesn't this way:

sage: def g(x,a):
....:     return numerical_integral(f(x,a),0,1, params=[a])
....:
sage: g(x,6)
(2.9999999999999996, 3.330669073875469e-14)


There's still something to figure out here!

A few observations.

1. A note. When you feed numerical_integral with the input f(x,a) into numerical_integral, it already detects that the input has two variables and knows that a one of them is a parameter. parameter. The optional input params is a way for you to lets one give the valuevalues of the parameters.

sage: var('x a')
sage: f(x,a)=a*x
sage: numerical_integral(f(x,a),0,1, params=[1])
(0.5, 5.551115123125783e-15)
sage: numerical_integral(f(x,a),0,1, params=[6])
(2.9999999999999996, 3.330669073875469e-14)


I'm 3.330669073875469e-14)

2. What is not sure exactly what happens when clear is which of the two variables in f is considered by numerical_integral as being the parameter. Is it x or a? Which is the main variable, the first one or the last one, or can it be specified?

3. A surprise. When you evaluate

sage: numerical_integral(f(x,a),0,1, params=[a])
(0.3333333333333333, 3.700743415417188e-15)
4. 
 it seems that the parameter is transformed into the main variable before integrating: the answer is exactly the integral of $x^2$ (or $a^2$ if the integration is with respect to $a$) from 0 to 1. sage: numerical_integral(x^2,0,1,) (0.3333333333333333, 3.700743415417188e-15) --- Not sure if this behaviour is wanted or a bug. Weirder (if you thought a was the parameter and x the main variable): sage: f(x,a)=a*x^2 sage: numerical_integral(f(x,a),0,1, params=[1]) (0.5, 5.551115123125783e-15) sage: numerical_integral(f(x,a),0,1, params=[a]) (0.25, 2.7755575615628914e-15) Now the integral with parameter set to 1 is wrong, unless integration is with respect to $a$ rather than $x$. With params=[a] it would seem that the parameter disappears (or is given the value 1). This means your g(x,a) defined as sage: g(x,a)=numerical_integral(f(x,a),0,1, params=[a]) doesn't now looks like x was set to a before integrating with respect to a. Since numerical_integral(f(x,a),0,1, params=[a]) has a fixed value, when you define sage: g(x,a) = numerical_integral(f(x,a),0,1, params=[a]) this does not depend on x or a, so g(x,anything)g(anything,anything) will always get you always return the same value. For some reason, it the "same" g defined using def doesn't this way: behave the same: sage: def g(x,a): ....: return numerical_integral(f(x,a),0,1, params=[a]) ....: sage: g(x,6) (2.9999999999999996, 3.330669073875469e-14) There's still something to figure out here! 3.330669073875469e-14) 

 3 No.3 Revision updated 2013-05-01 00:21:25 -0500 A few observations. A note. When you feed numerical_integral with the input f(x,a), it detects that the input has two variables and knows one of them is a parameter. The optional input params lets one give the values of the parameters. sage: var('x a') sage: f(x,a)=a*x sage: numerical_integral(f(x,a),0,1, params=[1]) (0.5, 5.551115123125783e-15) sage: numerical_integral(f(x,a),0,1, params=[6]) (2.9999999999999996, 3.330669073875469e-14)3.330669073875469e-14) What is not clear is which of the two variables in f is considered by numerical_integral as being the parameter. Is it x or a? Which is the main variable, the first one or the last one, or can it be specified? A surprise. When you evaluate sage: numerical_integral(f(x,a),0,1, params=[a]) (0.3333333333333333, 3.700743415417188e-15) 3.700743415417188e-15) it seems that the parameter is transformed into the main variable before integrating: the answer is exactly the integral of $x^2$ (or $a^2$ if the integration is with respect to $a$) from 0 to 1. sage: numerical_integral(x^2,0,1,) (0.3333333333333333, 3.700743415417188e-15) Not sure if this behaviour is wanted or a bug. Weirder (if you thought a was the parameter and x the main variable): sage: f(x,a)=a*x^2 sage: numerical_integral(f(x,a),0,1, params=[1]) (0.5, 5.551115123125783e-15) sage: numerical_integral(f(x,a),0,1, params=[a]) (0.25, 2.7755575615628914e-15) 2.7755575615628914e-15) Now the integral with parameter set to 1 is wrong, unless integration is with respect to $a$ rather than $x$. With params=[a] it now looks like x was set to a before integrating with respect to a. Since numerical_integral(f(x,a),0,1, params=[a]) has a fixed value, when you define sage: g(x,a) = numerical_integral(f(x,a),0,1, params=[a]) params=[a]) this does not depend on x or a, so g(anything,anything) will always return the same value. For some reason, the "same" g defined using def doesn't behave the same: sage: def g(x,a): ....: return numerical_integral(f(x,a),0,1, params=[a]) ....: sage: g(x,6) (2.9999999999999996, 3.330669073875469e-14)3.330669073875469e-14) 4 No.4 Revision updated 2013-05-01 00:33:18 -0500 A few observations. A note. When you feed numerical_integral with the input f(x,a), it detects that the input has two variables and knows one of them is a parameter. The optional input params lets one give the values of the parameters. sage: var('x a') sage: f(x,a)=a*x sage: numerical_integral(f(x,a),0,1, params=[1]) (0.5, 5.551115123125783e-15) sage: numerical_integral(f(x,a),0,1, params=[6]) (2.9999999999999996, 3.330669073875469e-14) What is not clear is which of the two variables in f is considered by numerical_integral as being the parameter. Is it x or a? Which is the main variable, the first one or the last one, or can it be specified? A surprise. When you evaluate sage: numerical_integral(f(x,a),0,1, params=[a]) (0.3333333333333333, 3.700743415417188e-15) it seems that the parameter is transformed into the main variable before integrating: the answer is exactly the integral of $x^2$ (or $a^2$ if the integration is with respect to $a$) from 0 to 1. sage: numerical_integral(x^2,0,1,) (0.3333333333333333, 3.700743415417188e-15) Not sure if this behaviour is wanted or a bug. Weirder (if you thought a was the parameter and x the main variable): sage: f(x,a)=a*x^2 sage: numerical_integral(f(x,a),0,1, params=[1]) (0.5, 5.551115123125783e-15) sage: numerical_integral(f(x,a),0,1, params=[a]) (0.25, 2.7755575615628914e-15) Now the integral with parameter set to 1 is wrong, unless integration is with respect to $a$ rather than $x$. With params=[a] it now looks like x was set to a before integrating with respect to a. Since numerical_integral(f(x,a),0,1, params=[a]) has a fixed value, when you define sage: g(x,a) = numerical_integral(f(x,a),0,1, params=[a]) this does not depend on x or a, so g(anything,anything) will always return the same value. For some reason, the "same" g defined using def doesn't behave the same: sage: def g(x,a): ....: return numerical_integral(f(x,a),0,1, params=[a]) ....: sage: g(x,6) (2.9999999999999996, 3.330669073875469e-14) Here, g(x,6) returns numerical_integral(f(x,6),0,1, params=[6]), in which the function to integrate only has one variable, x, and the optional parameter params=[6] is just ignored. You could simply write: sage: def g(a): ....: return numerical_integral(f(x,a),0,1) ....: sage: g(6) (2.9999999999999996, 3.330669073875469e-14) 5 No.5 Revision updated 2013-05-01 00:50:01 -0500 A few observations.observations can help explain what you are experiencing. A note. When you feed numerical_integral with the input f(x,a), it detects that the input has two variables and knows one of them is a parameter. The optional input params lets one give the values of the parameters. sage: var('x a') sage: f(x,a)=a*x sage: numerical_integral(f(x,a),0,1, params=[1]) (0.5, 5.551115123125783e-15) sage: numerical_integral(f(x,a),0,1, params=[6]) (2.9999999999999996, 3.330669073875469e-14) What is not clear is which of the two variables in f is considered by numerical_integral as being the parameter. Is it x or a? Which is the main variable, the first one or the last one, or can it be specified? A surprise. When you evaluate sage: numerical_integral(f(x,a),0,1, params=[a]) (0.3333333333333333, 3.700743415417188e-15) it seems that the parameter is transformed into the main variable before integrating: the answer is exactly the integral of $x^2$ (or $a^2$ if the integration is with respect to $a$) from 0 to 1. sage: numerical_integral(x^2,0,1,) (0.3333333333333333, 3.700743415417188e-15) Not sure if this behaviour is wanted or a bug. Weirder (if you thought a was the parameter and x the main variable): sage: f(x,a)=a*x^2 sage: numerical_integral(f(x,a),0,1, params=[1]) (0.5, 5.551115123125783e-15) sage: numerical_integral(f(x,a),0,1, params=[a]) (0.25, 2.7755575615628914e-15) Now the integral with parameter set to 1 is wrong, unless integration is with respect to $a$ rather than $x$. With params=[a] it now looks like x was set to a before integrating with respect to a. Since numerical_integral(f(x,a),0,1, params=[a]) has a fixed value, when you define sage: g(x,a) = numerical_integral(f(x,a),0,1, params=[a]) this does not depend on x or a, so g(anything,anything) will always return the same value. For some reason, the "same" g defined using def doesn't behave the same: sage: def g(x,a): ....: return numerical_integral(f(x,a),0,1, params=[a]) ....: sage: g(x,6) (2.9999999999999996, 3.330669073875469e-14) Here, g(x,6) returns numerical_integral(f(x,6),0,1, params=[6]), in which the function to integrate only has one variable, x, and the optional parameter params=[6] is just ignored. You could simply write: sage: def g(a): ....: return numerical_integral(f(x,a),0,1) ....: sage: g(6) (2.9999999999999996, 3.330669073875469e-14) So which one is the main variable? In numerical_integral(f(x,a),0,1,params=[value]), the function of several variables is treated as a function of one variable with parameters, but the main variable is a, not x. You might think the main variable is the last of the arguments of f(x,a) but it seems that it's really the first variable in the lexicographic order. Indeed, compare sage: f(x,y)=y*x^2 sage: numerical_integral(f(x,y),0,1, params=[1]) (0.3333333333333333, 3.700743415417188e-15) and sage: f(x,a)=a*x^2 sage: numerical_integral(f(x,a),0,1, params=[1]) (0.5, 5.551115123125783e-15) Can you change which variable is the main variable and which are parameters? I haven't figured that out yet. 


 Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license. about | faq | help | privacy policy | terms of service Powered by Askbot version 0.7.56 Please note: Askbot requires javascript to work properly, please enable javascript in your browser, here is how //IE fix to hide the red margin var noscript = document.getElementsByTagName('noscript')[0]; noscript.style.padding = '0px'; noscript.style.backgroundColor = 'transparent'; askbot['urls']['mark_read_message'] = '/messages/markread/'; askbot['urls']['get_tags_by_wildcard'] = '/get-tags-by-wildcard/'; askbot['urls']['get_tag_list'] = '/get-tag-list/'; askbot['urls']['follow_user'] = '/followit/follow/user/{{userId}}/'; askbot['urls']['unfollow_user'] = '/followit/unfollow/user/{{userId}}/'; askbot['urls']['user_signin'] = '/account/signin/'; askbot['urls']['getEditor'] = '/get-editor/'; askbot['urls']['apiGetQuestions'] = '/api/get_questions/'; askbot['urls']['ask'] = '/questions/ask/'; askbot['urls']['questions'] = '/questions/'; askbot['settings']['groupsEnabled'] = false; askbot['settings']['static_url'] = '/m/'; askbot['settings']['minSearchWordLength'] = 4; askbot['settings']['mathjaxEnabled'] = true; askbot['settings']['sharingSuffixText'] = ''; askbot['settings']['errorPlacement'] = 'after-label'; askbot['data']['maxCommentLength'] = 800; askbot['settings']['editorType'] = 'markdown'; askbot['settings']['commentsEditorType'] = 'rich-text'; askbot['messages']['askYourQuestion'] = 'Ask Your Question'; askbot['messages']['questionSingular'] = 'question'; askbot['messages']['answerSingular'] = 'answer'; askbot['messages']['acceptOwnAnswer'] = 'accept or unaccept your own answer'; askbot['messages']['followQuestions'] = 'follow questions'; askbot['settings']['allowedUploadFileTypes'] = [ "jpg", "jpeg", "gif", "bmp", "png", "tiff" ]; askbot['data']['haveFlashNotifications'] = true; askbot['data']['activeTab'] = 'questions'; askbot['settings']['csrfCookieName'] = 'asksage_csrf'; askbot['data']['searchUrl'] = ''; /*<![CDATA[*/ $('.mceStatusbar').remove();//a hack to remove the tinyMCE status bar$(document).ready(function(){ // focus input on the search bar endcomment var activeTab = askbot['data']['activeTab']; if (inArray(activeTab, ['users', 'questions', 'tags', 'badges'])) { var searchInput = $('#keywords'); } else if (activeTab === 'ask') { var searchInput =$('#id_title'); } else { var searchInput = undefined; animateHashes(); } if (searchInput) { searchInput.focus(); putCursorAtEnd(searchInput); } var haveFullTextSearchTab = inArray(activeTab, ['questions', 'badges', 'ask']); var haveUserProfilePage = $('body').hasClass('user-profile-page'); if ((haveUserProfilePage || haveFullTextSearchTab) && searchInput && searchInput.length) { var search = new FullTextSearch(); askbot['controllers'] = askbot['controllers'] || {}; askbot['controllers']['fullTextSearch'] = search; search.setSearchUrl(askbot['data']['searchUrl']); if (activeTab === 'ask') { search.setAskButtonEnabled(false); } search.decorate(searchInput); } else if (activeTab === 'tags') { var search = new TagSearch(); search.decorate(searchInput); } if (askbot['data']['userIsAdminOrMod']) {$('body').addClass('admin'); } if (askbot['settings']['groupsEnabled']) { askbot['urls']['add_group'] = "/add-group/"; var group_dropdown = new GroupDropdown(); $('.groups-dropdown').append(group_dropdown.getElement()); } var userRep =$('#userToolsNav .reputation'); if (userRep.length) { var showPermsTrigger = new ShowPermsTrigger(); showPermsTrigger.decorate(userRep); } }); if (askbot['data']['haveFlashNotifications']) { $('#validate_email_alert').click(function(){notify.close(true)}) notify.show(); } var langNav =$('.lang-nav'); if (langNav.length) { var nav = new LangNav(); nav.decorate(langNav); } /*]]>*/ if (typeof MathJax != 'undefined') { MathJax.Hub.Config({ extensions: ["tex2jax.js"], jax: ["input/TeX","output/HTML-CSS"], tex2jax: {inlineMath: [["$","$"],["\$","\$"]]} }); } else { console.log('Could not load MathJax'); } var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); try { var pageTracker = _gat._getTracker('UA-61392941-1'); pageTracker._trackPageview(); } catch(err) {} //todo - take this out into .js file $(document).ready(function(){$('div.revision div[id^=rev-header-]').bind('click', function(){ var revId = this.id.substr(11); toggleRev(revId); }); lanai.highlightSyntax(); }); function toggleRev(id) { var arrow = $("#rev-arrow-" + id); var visible = arrow.attr("src").indexOf("hide") > -1; if (visible) { var image_path = '/m/default/media/images/expander-arrow-show.gif?v=19'; } else { var image_path = '/m/default/media/images/expander-arrow-hide.gif?v=19'; } image_path = image_path + "?v=19"; arrow.attr("src", image_path);$("#rev-body-" + id).slideToggle("fast"); } for (url_name in askbot['urls']){ askbot['urls'][url_name] = cleanUrl(askbot['urls'][url_name]); }