题
我想这不成功:
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
解决方案
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'
)
其他提示
我觉得你的问题是,quadratic_residues可能并不意味着什么,你认为它的意思。如果您正试图以适应最好的二次模型我想你想要做这样的事情。
var('a, b, c, x')
model(x) = a*x*x + b*x + c
find_fit(data, model)
试图史蒂芬他的例子我还跑进错误:
ValueError: each row of data needs 5 entries, only 2 entries given
下面是在鼠尾草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]
Apperently你需要的变量= [X]告诉鼠尾草其中的a,b,c和x对应于变量模型中的
不隶属于 StackOverflow