Dear Ahmed Fasih

Thanks a lots for and for the instructions to insert a patch. I would 
have not never thought it was so easy to insert a patch in Sage!!!!! You 
save me a lot of time !!!

And even the code inserted in the patch does not look to difficult... I 
am looking forward to collaborating with Sage.

Thanks a lot!

Jose
wrote:
> Jose, I just tried this in a Notebook for a Sage having applied the
> patch as described in 
> http://groups.google.com/group/sage-support/msg/00d0b4c724473e3c
> and it works:
> <<<
> import numpy as np
> from scipy.optimize import leastsq
> 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))
>   
>
> produces:
>
> (array([ 4.90502425,  1.99999494]), 3)
>
> See the thread for details, but for completeness, I am copying the
> relevant bit from wstein's mail:
> <<<
> sage: hg_sage.apply('http://trac.sagemath.org/sage_trac/attachment/
> ticket/5081/5081-numpy-types.patch')
> sage: quit
> $ sage -br
> ... wait a few minutes
>   
>
> On Jul 27, 10:29 am, Jose Guzman <[email protected]> wrote:
>   
>> HI Minh Nguyen"!
>>
>>
>>
>>     
>>> I got this far:
>>>       
>>> ----------------------------------------------------------------------
>>> | Sage Version 4.1, Release Date: 2009-07-09                         |
>>> | Type notebook() for the GUI, and license() for information.        |
>>> ----------------------------------------------------------------------
>>> sage: import numpy as np
>>> sage: import scipy.optimize
>>> sage: x = np.arange(0, 3.0, 0.25)
>>> sage: 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)
>>> sage: def residuals(p, x, y):
>>> ....:     k, degree = p
>>> ....:     err = y -(k*(x^degree))
>>> ....:     return err
>>> ....:
>>> sage: pinit = [4.0, 3]
>>> sage: scipy.optimize.leastsq(residuals, pinit, args=(x,y))
>>> ---------------------------------------------------------------------------
>>> TypeError                                 Traceback (most recent call last)
>>>       
>>> /home/mvngu/.sage/temp/sage.math.washington.edu/28595/_home_mvngu__sage_init_sage_0.py
>>> in <module>()
>>>       
>>> /usr/local/sage/local/lib/python2.6/site-packages/scipy/optimize/minpack.pyc
>>> in leastsq(func, x0, args, Dfun, full_output, col_deriv, ftol, xtol,
>>> gtol, maxfev, epsfcn, factor, diag, warning)
>>>     268         if (maxfev == 0):
>>>     269             maxfev = 200*(n+1)
>>> --> 270         retval =
>>> _minpack._lmdif(func,x0,args,full_output,ftol,xtol,gtol,maxfev,epsfcn,factor,diag)
>>>     271     else:
>>>     272         if col_deriv:
>>>       
>>> TypeError: array cannot be safely cast to required type
>>>       
>>> As mentioned at the thread
>>>       
>>> http://groups.google.com/group/sage-devel/browse_thread/thread/fd1414...
>>>       
>>> the problem is that at the moment there is little support for
>>> automatic data conversion between NumPy and Sage. Here are some
>>> tickets to make this happen:
>>>       
>>> #6497
>>> http://trac.sagemath.org/sage_trac/ticket/6497
>>>       
>>> #5081
>>> http://trac.sagemath.org/sage_trac/ticket/5081
>>>       
>>> #6506
>>> http://trac.sagemath.org/sage_trac/ticket/6506
>>>       
>> ok, I got it, I will have a look to that. I guess this might be a good
>> occasion to contribute to the Sage code. I will have a look to the
>> developers guide.
>>     
> >
>   


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to