| 1 | initial version |
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!
| 2 | No.2 Revision |
A few observations.
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 one of them is a a parameter. parameter.
The optional input params is a way for you to lets one give the valuevalues of the parameters.
I'm
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?
A surprise. When you evaluate
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 will g(x,anything)g(anything,anything)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 |
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, 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, 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, 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, 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, | 4 | No.4 Revision |
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 |
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.