5

我试过这个不成功:

find_fit(data, quadratic_residues)

我正在尝试找到最适合有关水流量的数据:http: //dl.getdropbox.com/u/175564/rate.png

---评论后编辑---

新代码:

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

错误信息:

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

- -编辑

错误消息现在是:

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

这里和图片一样: http: //dl.getdropbox.com/u/175564/sage.png

4

3 回答 3

7
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'
  )
于 2012-08-04T18:05:12.447 回答
3

我认为你的问题是 quadratic_residues 可能并不意味着你认为它意味着什么。如果你试图拟合最好的二次模型,我想你想做类似的事情。

var('a, b, c, x')
model(x) = a*x*x + b*x + c
find_fit(data, model)
于 2009-01-18T05:45:00.007 回答
2

尝试 Steven 他的例子我也遇到了错误:

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

这是一个更明确的示例,我已经测试过它可以在 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]

显然,您需要 variables=[x] 来告诉 sage a、b、c 和 x 中的哪一个对应于模型中的变量。

于 2012-07-01T17:00:12.440 回答