Thanks for the quick reply Harald.
> the question is, what is .dat. if it is csv like, there are methods to
> read it. depends on .dat! python is even able to read from xls.
>
Actually I meant an arbitrarily formatted .csv-type file (tabs instead
of commas). As I see the python "csv"-module does quite well.
import csv
data = [row for row in csv.reader(open('.dat'), delimiter='\t ')]
did the trick for me.
> there is a "find_fit" function, new since 3.2.1.
>
> First we create some datapoints of a sine function with some random
> perturbations:
> sage: data = [(i, 1.2 * sin(0.5*i-0.2) + 0.1 * normalvariate(0, 1))
> for i in xsrange(0, 4*pi, 0.2)]
> sage: var('a, b, c, x')
> (a, b, c, x)
>
> We define a function with free parameters a, b and c:
> sage: model(x) = a * sin(b * x - c)
>
> We search for the parameters that give the bestfitto the data:
> sage: find_fit(data, model)
> [a == 1.21..., b == 0.49..., c == 0.19...]
>
Thanks a lot!!! That was what I was searching for.
> The benefits of using R as you mentioned is, that you get an analysis
> about the linear or generalized linear model about the errors, amount
> of "explanation" for each part of the fitted result, anova, and so on.
> Plotting should be straight forward.
Sure, learning R is definitely a future goal of mine. Suppose there is
no good way to get the standard error or correlation matrix in sage?
Guess for me it's either back to gnuplot/origin or forward to R...
> Use the "solution_dict" parameter
> if you want to use the result for substitutions.
That doesn't work too well.. My code reads:
sage: import csv
sage: data = [row for row in csv.reader(open('diode.dat'),
delimiter='\t')]
sage: a,b,c,d = var('a b c
d')
sage: model(x) = a + b * exp(c*x +
d)
sage: fit = find_fit(data,model,solution_dict=True)
sage: a, b, c, d = fit[a],fit[b],fit[c],fit[d]
and does not work.. Only if I modify the last line to
a = fit[a]; b = fit[b]; c = fit[c]; d = fit[d]
it works as it should. Afterwards I proceed with:
modelnum(x) = a + b * exp(c*x + d)
p1 = list_plot(data,rgbcolor=(1,0,0)); p2 = plot(modelnum); (p1 +
p2).show
and get almost what I wanted.. Almost, because I still have to worry
about plot-details like crosses, data-labels, x-axislabels. As William
pointed out half a year ago (http://groups.google.com/group/sage-
support/browse_thread/thread/8e5cec4fe1302ea5/feea3b2a2a12ae47?
lnk=gst&q=plot#feea3b2a2a12ae47) best thing is to use pylab for
plotting.
Has that changed? Can anyone help me from this point on? How do I most
automatically display the data and fit produced with this method (i.e.
replace the last line by somethin nice)?
Thanks in advance
---
for people beeing as new as me with sage plotting. Here's a nice
video: http://showmedo.com/videos/series?name=QZ0PAxn60
--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---