On Thu, Jul 12, 2012 at 2:57 PM, Urs Hackstein
<[email protected]> wrote:
> Dear all,
>
> unfortunately I couldn't find any explanations on a least squares solution
> routine in Sage. http://www.sagemath.org/doc/numerical_sage/scipy.html tells
> me that there exists one, but the documentation is still to be written. Thus
> my question is whether someone could explain how to call this routine.
> I have given 18 points which I want to interpolate by a function of the type
> (a_8*x^8+a_7*x^7+a_6*x^6+a_5*x^5+a_4*x^4+a_3*x^3+a_2*x^2+a_1*x^1+a_0)/(b_8*x^8+b_7*x^7+b_6*x^6+b_5*x^5+b_4*x^4+b_3*x^3+b_2*x^2+b_1*x^1+b_0).
Note that I am a newby so take this with a grain of salt. I think
find_fit could be what you are looking for. This kind of works:
xx = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
yy = [0, 4, 6, 8, 12, 15, 20, 24, 32, 45, 56, 67, 73, 83, 99, 109, 124, 129]
points = zip(xx, yy)
var('a_8, a_7, a_6, a_5, a_4, a_3, a_2, a_1, a_0, b_8, b_7, b_6, b_5,
b_4, b_3, b_2, b_1, b_0, x, y')
model(x) = (a_8*x^8 + a_7*x^7+ a_6*x^6 + a_5*x^5 + a_4*x^4 + a_3*x^3 +
a_2*x^2 + a_1*x + a_0) / (b_8*x^8 + b_7*x^7 + b_6*x^6 + b_5*x^5 +
b_4*x^4 + b_3*x^3 + b_2*x^2 + b_1*x + b_0)
fit = find_fit(points, model, solution_dict=True)
drawCurve = plot(model.subs(fit), (x, min(xx), max(xx)))
drawPoints = list_plot(points, size=30, color = 'purple')
figure = drawCurve + drawPoints
figure.show()
show(model)
show(fit)
--
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
URL: http://www.sagemath.org