4
$\begingroup$

I have the following Data:

ExpDataCycles = {23, 69, 39, 25, 6, 43, 431, 328, 130, 614, 5941, 
   4506, 1876, 7898, 27015, 19154, 11586, 21470,
   130885, 431405, 84036, 1003250};
ExpDataMpa = {835.0265363, 823.4175447, 810.7696175, 799.6485919, 
   794.4425228, 793.0602069, 707.6873459,
   704.8236368, 693.9200675, 687.0103167, 609.8345095,
   602.6188024, 598.086902, 595.6103517, 591.5466695,
   584.7172701, 559.4813142, 556.6416481, 551.1841848,
   541.232457, 539.3158579, 385.3438704};

Which I plot using ListLogLinearPlot

ListLogLinearPlot[Transpose[{ExpDataCycles, ExpDataMpa}], 
 PlotRange -> Automatic, AxesLabel -> {"Cycles [N]", "Stress Mpa"}, 
 PlotLabel -> "S-N Cyclic Loading Life at R = -1 "]

enter image description here

I'm trying to plot a best fit curve using least squares.

I plot using:

ExpDataCyclesMpa = Transpose[{ExpDataCycles, ExpDataMpa}];
LeastSqr = Fit[ExpDataCyclesMpa, {1, x, x^2}, x];
Show[ListLogLinearPlot[Transpose[{ExpDataCycles, ExpDataMpa}]], 
 Plot[LeastSqr, {x, 0, 1100000}]]

enter image description here

I understand the issue of the straight lines which i thick is because my x-axis is in Log form. How can I Plot a quadratic least squares fit between the LinearLog graph?

$\endgroup$

3 Answers 3

5
$\begingroup$

@rcollyer's answer is 100% correct, though it is telling that the ListLogLinearPlot of your data follows a polynomial shape. This tells me that your y-values follows a polynomial function with your Log[x] values. The plots seem to confirm this, as the curve fits your data much better:

Clear[ExpDataCyclesMpa, LeastSqr]
ExpDataCyclesMpa = Transpose[{ExpDataCycles, ExpDataMpa}];
LeastSqr = Fit[Transpose[{ExpDataCycles, ExpDataMpa}], {1, Log@x, (Log@x)^2}, x];
Show[ListLogLinearPlot[ExpDataCyclesMpa], LogLinearPlot[LeastSqr, {x, 1, 1100000}]]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ exactly what I need! Thanks guys! $\endgroup$
    – Nikolas
    Jul 17, 2014 at 20:31
  • $\begingroup$ Ok. So, I took the easy way out, +1. :) $\endgroup$
    – rcollyer
    Jul 17, 2014 at 21:10
3
$\begingroup$

Use LogLinearPlot, instead:

ExpDataCyclesMpa = Transpose[{ExpDataCycles, ExpDataMpa}];
LeastSqr = Fit[ExpDataCyclesMpa, {1, x, x^2}, x];
Show[ListLogLinearPlot[Transpose[{ExpDataCycles, ExpDataMpa}]], 
 LogLinearPlot[LeastSqr, {x, 1, 1100000}]]

enter image description here

$\endgroup$
2
  • $\begingroup$ @rcollyer.Thanks for the input but now I that I see the graph i might have formulated my question wrong. Basically I want a bestfit between the points.. Can you help on this? $\endgroup$
    – Nikolas
    Jul 17, 2014 at 20:29
  • $\begingroup$ @Nikolas perhaps my answer might help you on that. $\endgroup$
    – seismatica
    Jul 17, 2014 at 20:30
1
$\begingroup$

An Alternative:

a = Transpose[{ExpDataCycles, ExpDataMpa}];

b = Interpolation[a, InterpolationOrder -> 2];

c = LogLinearPlot[b[x], {x, 6., 10^6.}, GridLines -> Automatic];

d = ListLogLinearPlot[a, PlotStyle -> Red];

Show[c, d, PlotRange -> All, ImageSize -> 400]

enter image description here

$\endgroup$
3
  • $\begingroup$ Groovy! Thanks for the cool trick. $\endgroup$
    – seismatica
    Jul 17, 2014 at 20:47
  • $\begingroup$ PS. Are you using MMA 9? I use MMA 10 an I could not get the minor grid lines to show up (screenshot). $\endgroup$
    – seismatica
    Jul 17, 2014 at 20:57
  • $\begingroup$ @Seismatic Yes it's MMA 9 (I don't have 10). $\endgroup$
    – eldo
    Jul 17, 2014 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.