www.GetXFactor.com

Leading Technology, Science,
Agriculture News and information


Part of the Identityscape.com network...

getxfactor.com jmoodmusic.com smartbusinesschoices.com mintdepot.com lowfaresalways.com evangelicalview.com shoppingpodder.com soproudlywehail.com webnews.ws currenthumor.com

 

 

How to fit Log[] data in Mathematica?
   Science and Technology news... Forum Index -> Math - Symbolic Forum  
View previous topic :: View next topic  
Author Message
Karen Bindash
Guest






PostPosted: Fri Jul 25, 2008 12:35 pm    Post subject: How to fit Log[] data in Mathematica? Reply with 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.

2) How can I create a fit on the assumption that y = a + b Log[10,x] +
c*Log[10,x]^2 + d Log[10,x]^3 ?

3) Assuming I can get a Plot of the fit, and a ListPlot of the
original data, would the best way to show them on the same graph be to
use Show[], or is there a better way? I>ve had problems doing this in
the past, where I>ve never managed to work out what the axes will be
or the label, PlotLabel etc.


anyone any concrete examples for thi.
Back to top
Karen Bindash
Guest






PostPosted: Fri Jul 25, 2008 1:53 pm    Post subject: Re: How to fit Log[] data in Mathematica? Reply with quote

On Jul 25, 2:35 pm, Dave <f...@coo.com> wrote:
[quote]Karen Bindash wrote:
I have some data consisting of xy pairs {{x1,y1},{x2,y2},{x3,y3}...}

I>m not quite sure why you have posted this 3 times, with slight
changes, but:.
[/quote]
Sorry, I did change the message a couple of times and delete it, but I
only see it once myself. Perhaps you can see it in a way I can>t.

[quote]
I doubt very much this is efficient (I never really have understood how
best to manipulate lists in Mathematica, I>m sure I often call Transpose
and similar things far too much), but you could try the following.
[/quote]
Thank you, I will look at that. As you guessed, the point I have was
wrong.

Does anyone know if the method below is efficient or not? My data set
is much larger, so it would be nice to have something that is as
efficient as possible.

[quote]This plots the two. The fit is not very good, but ...

Show[Plot[fit, {x, 10, 1000000}], ListPlot[data]]

Dave
[/quote]
Thank you. It seems I might have to look for something else to try to
fit.

I would be very interested in a more efficient way, as my dataset is
very large.

Karen
Back to top
Dave
Guest






PostPosted: Fri Jul 25, 2008 6:35 pm    Post subject: Re: How to fit Log[] data in Mathematica? Reply with quote

Karen Bindash wrote:
[quote]I have some data consisting of xy pairs {{x1,y1},{x2,y2},{x3,y3}...}
[/quote]
I>m not quite sure why you have posted this 3 times, with slight
changes, but:.

[quote]
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.
[/quote]
I assume the {100000,408} should be {100000,40.8} then ??? As it is, the
y range is not limited to the range 34.3 to 41.2.


[quote]
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]
It will not be straight with the 408 in there, but if its 40.8, perhaps
it will.

[quote]
2) How can I create a fit on the assumption that y = a + b Log[10,x] +
c*Log[10,x]^2 + d Log[10,x]^3 ?
[/quote]
I doubt very much this is efficient (I never really have understood how
best to manipulate lists in Mathematica, I>m sure I often call Transpose
and similar things far too much), but you could try the following.

In[1]:= data = {{10, 34.2}, {30, 36.7}, {100, 38.2}, {300, 39}, {1000,
39.6}, {3000, 40}, {10000, 40.4}, {30000, 40.6}, {100000,
40.8}, {300000, 41.1}, {1000000, 41.2}}

Out[1]= {{10, 34.2}, {30, 36.7}, {100, 38.2}, {300, 39}, {1000, 39.6},

[quote]{3000, 40}, {10000, 40.4}, {30000, 40.6}, {100000, 40.8},

{300000, 41.1}, {1000000, 41.2}}
[/quote]
In[2]:= logx = Log[10.0, Take[Flatten[data], {1, -1, 2}]]

Out[2]= {1., 1.47712, 2., 2.47712, 3., 3.47712, 4., 4.47712, 5.,
5.47712, 6.}

In[3]:= y = Take[Flatten[data], {2, -1, 2}]

Out[3]= {34.2, 36.7, 38.2, 39, 39.6, 40, 40.4, 40.6, 40.8, 41.1, 41.2}

In[4]:= log10data = Transpose[{logx, y}]

Out[4]= {{1., 34.2}, {1.47712, 36.7}, {2., 38.2}, {2.47712, 39}, {3., 39.6},

[quote]{3.47712, 40}, {4., 40.4}, {4.47712, 40.6}, {5., 40.8}, {5.47712,
41.1},[/quote]

[quote]{6., 41.2}}
[/quote]

In[6]:= fit = Fit[log10data, {1, k, k^2, k^3}, k] /. k -> Log[10, x]

2 3
Out[6]= 28.2703 + 3.34087 Log[x] - 0.312086 Log[x] + 0.0100491 Log[x]



[quote]
3) Assuming I can get a Plot of the fit, and a ListPlot of the
original data, would the best way to show them on the same graph be to
use Show[], or is there a better way? I>ve had problems doing this in
the past, where I>ve never managed to work out what the axes will be
or the label, PlotLabel etc.
[/quote]

This plots the two. The fit is not very good, but ...

Show[Plot[fit, {x, 10, 1000000}], ListPlot[data]]

Dave
Back to top
Display posts from previous:   
   Science and Technology news... Forum Index -> Math - Symbolic Forum  
Page 1 of 1
All times are GMT

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum