On Sat, Jan 10, 2009 at 8:29 PM, slybro <sntve...@gmail.com> wrote:
>
> I am having trouble using the polyfit function. Here are the
> commands:
>
> import numpy as np
> import scipy as sc
>
> vp = np.array([1.0, 5.0, 10.0, 20.0, 40.0, 60.0, 100.0, 200.0, 400.0,
> 760.0])
>
> T = np.array([-36.7, -19.6, -11.5, -2.6, 7.6, 15.4, 26.1, 42.2, 60.6,
> 80.1])
>
> (a,b,c,d) = np.polyfit(vp,T,3)
You must explicitly make the Numpy array's have dtype float as numpy
does not automatically convert Sage's RealNumber to a float. If you
don't do this, the array's dtype will be "object'.
sage: vp = np.array([1.0, 5.0, 10.0, 20.0, 40.0, 60.0, 100.0, 200.0,
400.0, 760.0],dtype=float)
sage: T = np.array([-36.7, -19.6, -11.5, -2.6, 7.6, 15.4, 26.1, 42.2,
60.6, 80.1], dtype=float)
sage: np.polyfit(vp,T,3)
array([ 1.13148994e-06, -1.49004659e-03, 6.12784745e-01,
-2.13934587e+01])
There are other ways to achieve a similar effect such as turning off
the Sage preparser with "preparser(False)" or making Sage's RealNumber
an alias of float ("RealNumber = float").
--Mike
Hi Michael:
On Jan 11, 3:04 pm, "Steve Yarbro" <sntventu...@gmail.com> wroteMichael...@mathematik.uni-dortmund.de:
Yes, you need to use zip in your case. list_plot takes a list of
points, like this:
list_plot([ (x1,y1), (x2,y2), (x3,y3)])
You were trying to pass it two lists, one of x coordinates and one of y
coordinates. This is how you would do things in matlab, but not Sage:
list_plot([x1, x2, x3], [y1, y2, y3])
The zip command just converts between these:
zip([x1,x2,x3], [y1,y2,y3]) is [(x1,y1), (x2,y2), (x3,y3)]
You can see the documentation for list_plot and zip by typing the
command name followed by a question mark:
list_plot?
zip?
Having said that, this confusion points to a bug in the list_plot
documentation. It should probably mention this and show how to use the
zip command.
Thanks,
Jason
Harald