Karen Bindash Guest
|
Posted: Fri Jul 25, 2008 10:52 am Post subject: How to fit data in Mathematica? |
|
|
I have some data consisting of xy pairs {{x1,y1},{x2,y2},{x3,y3}...}
data = {{10, 34.2}, {30, 36.7}, {100, 38.2}, {300, 39}, {1000,
39.6}, {3000, 40}, {10000, 40.4}, {30000, 40.6}, {100000,
408}, {300000, 41.1},{1000000,41.2}}
As you can see, x ranges from 10 to 1000000 as y ranges from 34.3 to
41.2.
1) How can I plot y against Log[10,x] ? i.e. I want the x-axis to go
from 1 to 6, and the y axis from 32 to 42. I think the graph will not
be too far from straight.
2) How can I create a fit on the assumption that y = a + b Log[10,x] +
c*Log[10,x)^2
Assuming I can get them, I assume I can use Show[] in combination
litploy.
Has anyone any concrete examples for thi. |
|
Nasser Abbasi Guest
|
Posted: Sat Jul 26, 2008 12:33 am Post subject: Re: How to fit data in Mathematica? |
|
|
"Karen Bindash" <KarenBindash@googlemail.com> wrote in message
news:e9d409f1-63cc-4d98-b9fb-ecbd32e54e80@x29g2000prd.googlegroups.com...
[quote]I have some data consisting of xy pairs {{x1,y1},{x2,y2},{x3,y3}...}
data = {{10, 34.2}, {30, 36.7}, {100, 38.2}, {300, 39}, {1000,
39.6}, {3000, 40}, {10000, 40.4}, {30000, 40.6}, {100000,
408}, {300000, 41.1},{1000000,41.2}}
As you can see, x ranges from 10 to 1000000 as y ranges from 34.3 to
41.2.
1) How can I plot y against Log[10,x] ? i.e. I want the x-axis to go
from 1 to 6, and the y axis from 32 to 42. I think the graph will not
be too far from straight.
[/quote]
x = (Log[10, #1] & )[data[[All,1]]];
y = data[[All,2]];
newData = N[Transpose[{x, y}]]
ListPlot[newData, Joined -> True, PlotRange -> All]
[quote]2) How can I create a fit on the assumption that y = a + b Log[10,x] +
c*Log[10,x)^2
[/quote]
(*make some values for the parameters
a = 1; b = 4; c = 2;
Clear[x]
newY = Fit[data, a + b*Log[10, x] + c*Log[10, x]^2, x];
[quote]Assuming I can get them, I assume I can use Show[] in combination
litploy.
[/quote]
Now you have all the data you need, you can easily combine the plots using
number of ways.
Nasser |
|