# Plot least squares curve on Linear Log Plot

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"},


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


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?

-

@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}]]


-
exactly what I need! Thanks guys! – Nikolas Jul 17 '14 at 20:31
Ok. So, I took the easy way out, +1. :) – rcollyer Jul 17 '14 at 21:10

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


-
@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? – Nikolas Jul 17 '14 at 20:29

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]


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