---------- Forwarded message ----------
From: Urs Hackstein <[email protected]>
Date: 2012/7/13
Subject: Re: [sage-support] least squares solutions
To: [email protected]


Dear Pablo Fernandez,

thanks a lot for your suggestion. Unfortunately, it does not work in my
case and the error sounds a bit strange to me. As you suggested, I tried
xx=[0.5*I, 1*I,
5*I,10*I,50*I,100*I,500*I,1000*I,5000*I,10000*I,5*10^4*I,10^5*I,5*10^5*I,10^6*I,5*10^6*I,10^7*I,5*10^7*I,10^8*I]
yy=[f_1,f_2,
f_3,f_4,f_5,f_6,f_7,f_8,f_9,f_10,f_11,f_12,f_13,f_14,f_15,f_16,f_17,f_18]
points = zip(xx, yy)
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)

but received the following error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_162.py", line 10, in <module>

    exec compile(u'open("___code___.py","w").write("# -*- coding:
utf-8 -*-\\n" +
_support_.preparse_worksheet_cell(base64.b64decode("ZmluZF9maXQocG9pbnRzLCBtb2RlbCk="),globals())+"\\n");
execfile(os.path.abspath("___code___.py"))

  File "", line 1, in <module>

  File "/tmp/tmpokpamM/___code___.py", line 2, in <module>
    exec compile(u'find_fit(points, model)
  File "", line 1, in <module>


  File 
"/usr/local/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py",
line 592, in find_fit
    raise TypeError, "data has to be a list of lists, a matrix, or a
numpy array"

TypeError: data has to be a list of lists, a matrix, or a numpy array

Any suggestion?

Urs Hackstein


2012/7/12 Pablo Fernandez <[email protected]>

> 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.htmltells
> > 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
>

-- 
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

Reply via email to