Hi there!

I am trying to find some parameters with the least squares algorithm 
within Sage (v 4.0.2) . Unfortunately, when I try to use the 
scipy.optimize.leastsq() method within Sage I get the following error:

 >>> array cannot be safely cast to required type.

Strange enough,  if I do the same directly with iPython I can perform 
the computation properly.  Do I have to cast my original data to some 
special type in Sage (i.e RealNumbers)???. If yes, how? I tried lists, 
tuples and NumPy arrays but  It did not work.

here the simplified code:

# some dummy  x,y data for testing
x = np.arange(0,3.0,0.25)
y = 
np.array([0.0,0.3066,1.2263,2.7591,4.9050,7.6641,11.0363,15.0216,19.6200,24.8316,30.6562,37.0941],dtype=float)

# define a residuals function
def residuals(p,x,y):
    k,degree = p
    err = y -(k*(x**degree))
    return err

# initial guess, k = 4.0, exp = 3?
pinit = [4.0,3]

#compute the leastsq algorithm
leastsq(residuals,pinit,args=(x,y))

Thank you very much in advance!

Jose.

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to