Pregunta

Intenté esto sin éxito:

find_fit(data, quadratic_residues)

Estoy tratando de encontrar el mejor ajuste para los datos sobre las tasas de flujo de agua: http : //dl.getdropbox.com/u/175564/rate.png

--- editar después del comentario ---

El nuevo código:

var('x')
model(x) = x**2
find_fit((xlist, reqlist), model)

El mensaje de error:

Traceback (click to the left for traceback)
...
TypeError: data has to be a list of lists, a matrix, or a numpy array

--- editar

El mensaje de error es ahora:

Traceback (click to the left for traceback)
...
ValueError: each row of data needs 2 entries, only 5 entries given

Lo mismo aquí que una imagen: http://dl.getdropbox.com/u/175564/sage.png

¿Fue útil?

Solución

mydata = [[1,3],[2,7],[3,13],[4,24]]
var('a,b,c')
mymodel(x) = a*x^2 + b*x + c 
myfit = find_fit(mydata,mymodel,solution_dict=True)
points(mydata,color='purple') + plot(
  mymodel(
    a=myfit[a],
    b=myfit[b],
    c=myfit[c]
    ), 
    (x,0,4,),
    color='red'
  )

Otros consejos

Creo que tu problema es que los residuos cuadráticos probablemente no significan lo que crees que significa. Si está intentando ajustar el mejor modelo cuadrático, creo que quiere hacer algo como eso.

var('a, b, c, x')
model(x) = a*x*x + b*x + c
find_fit(data, model)

Al intentar con Steven su ejemplo, también me encontré con el error:

ValueError: each row of data needs 5 entries, only 2 entries given

Aquí hay un ejemplo más explícito que he probado para trabajar en Sage 4.7.

sage: l=[4*i^2+7*i+134+random() for i in xrange(100)]
sage: var('a,b,c,x')
(a, b, c, x)
sage: model=a*x^2+b*x+c
sage: find_fit(zip(xrange(100),l),model,variables=[x])
[a == 4.0000723084513217, b == 6.9904742307159697, c == 134.74698715254667]

Aparentemente necesita las variables = [x] para decirle a Sage cuál de a, b, c y x corresponde a la variable en su modelo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top