ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 04 Apr 2013 11:49:56 -0500Piecewise curve fitting polynomial datahttp://ask.sagemath.org/question/9989/piecewise-curve-fitting-polynomial-data/Hello all. I am curve fitting time series data using polyfit() and it works well for most of my data sets. I have noticed, however, that some data sets begin hyperbolic and move to exponential so as to best fit to two separate equations. What is simple way to fit my data to two different curve equations using Sage? Is there a good mathematical or programmatic method of determining when a data set is best served by piecewise curve fitting? Currently, I can only determine that empirically once the curve is plotted along with the data points.
NatashaNatashaThu, 04 Apr 2013 11:49:56 -0500http://ask.sagemath.org/question/9989/Coercion problem while defining piecewise functionhttp://ask.sagemath.org/question/7895/coercion-problem-while-defining-piecewise-function/In a nutshell: I begin by defining the following function:
def g(x):
return math.exp(-1/(1 - x^2))
which poses no problem. Then, I try to use this function g to define a new function, as follows:
f = Piecewise([ [(-.5,.5), 0.44399*g(x)] ])
which returns the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Applications/sage/<ipython console> in <module>()
/Applications/sage/<ipython console> in g(x)
/Applications/sage/local/lib/python2.6/site-packages/sage/rings/fraction_field_element.so in sage.rings.fraction_field_element.FractionFieldElement.__float__ (sage/rings/fraction_field_element.c:8540)()
/Applications/sage/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.__float__ (sage/rings/polynomial/polynomial_element.c:8243)()
TypeError: cannot coerce nonconstant polynomial to float
-----------
I am not sure of what is going wrong here. Any ideas/solutions would be deeply appreciated.
-jl
Jose LykonMon, 24 Jan 2011 18:52:38 -0600http://ask.sagemath.org/question/7895/