[email protected] wrote:
> This will bomb because numerical_integral doesn't allow vars for the
> limits of integration:
> Y(t)=2500+numerical_integral(S(u)-R(u),0,t)[0]
>
> I tried Y(t)=2500+numerical_integral(S(u)-R(u),0,x).substitute(x=t)[0]
>
> and
>
> Y(t) = ( 2500+numerical_integral(S(u)-R(u),0,x)[0]).substitute(x=t)
How come n(integrate(some expression that doesn't integrate, x, 0, 1))
doesn't return the result of numerical_integral(same expression, 0, 1) ?
It seems that would solve the problem, as then you would just call
integrate normally in the above expression, so Y(t) would generally
return an unevaluated integral, and then you would just do n(Y(4)) to
get the numerical approximation given by numerical_integral.
Example:
sage: var('t')
t
sage: assume(t>0)
sage: a=(integrate(sin(cos(x)), 0, t)).subs(t=4)
sage: a
integrate(sin(cos(x)), x, 0, 4)
sage: n(a) # Why doesn't this return the result of numerical_integral?
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/jason/.sage/temp/littleone/29880/_home_jason__sage_init_sage_0.py
in <module>()
/home/jason/sage/local/lib/python2.5/site-packages/sage/misc/functional.pyc
in numerical_approx(x, prec, digits)
765 prec = int((digits+1) * 3.32192) + 1
766 try:
--> 767 return x.numerical_approx(prec)
768 except AttributeError:
769 from sage.rings.complex_double import
is_ComplexDoubleElement
/home/jason/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc
in numerical_approx(self, prec, digits)
1514 except TypeError:
1515 # try to return a complex result
-> 1516 approx = self._complex_mpfr_field_(ComplexField(prec))
1517
1518 return approx
/home/jason/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc
in _complex_mpfr_field_(self, field)
1748
1749 def _complex_mpfr_field_(self, field):
-> 1750 raise TypeError
1751
1752 def _complex_double_(self, C):
TypeError:
sage: numerical_integral(sin(cos(x)), 0, 4)
(-0.6589735634713888, 2.714926799945442e-14)
Jason
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---