# how to find linear fit

Anybody who can help me to make a linear fit if I have a specific number of intersection point (x0,y0), so instead of using this y=mx I have to use this y-y0=m(x-x0),x0 = 0.3459; y0 = 0.4478 so I need to get a straight line from fit function that can cross the point(x0,y0). Please look at my code below and let me know how I can modify fit function to work with the above equation .

     range = {{0.3389, 0.44079999999999997}, {0.3389,
0.4415}, {0.3389, 0.4422}, {0.3389,
0.44289999999999996}, {0.3396, 0.4436}, {0.34099999999999997,
0.4443}, {0.3417, 0.44499999999999995}, {0.34309999999999996,
0.4457}, {0.3438, 0.44639999999999996}, {0.3452,
0.4471}, {0.3459, 0.4478}, {0.34659999999999996,
0.44849999999999995}, {0.348, 0.4492}, {0.3487,
0.44989999999999997}, {0.35009999999999997, 0.4506}, {0.3508,
0.4513}, {0.35219999999999996, 0.45199999999999996}, {0.3529,
0.4527}, {0.3529, 0.45339999999999997}, {0.3529,
0.45409999999999995}, {0.3529, 0.4548}};
p = ListLinePlot[range, BaseStyle -> Red,
PlotRange -> {{0.342, 0.349}, {0.435, 0.455}}]
x = range[[All, 1]]
y = range[[All, 2]];
drop = Drop[Drop[range, 4], -4]
ListPlot[drop]
x0 = 0.3459;
y0 = 0.4478;
yy = Fit[drop, {0, xx}, xx]
pnew = Plot[yy, {xx, .335, .35}, PlotStyle -> {Black}]


• Please take another look at your code and your question. Should drop = Drop[Drop[data, 4], -4] be drop = Drop[Drop[range, 4], -4] ? I see no zeros but I see "duplicate" x-values at the beginning and the end of the list of data.
– JimB
Commented Mar 12, 2018 at 1:29
• Here is short cut for your function {x, y} = Transpose@range and drop = Take[range, {5, -5}] Commented Mar 12, 2018 at 13:06
• Thanks for your response. I corrected my question, so from my code I got a line that is not a straight line, but it is wavy and it doesn't cross the point (x0,y0). How I can modify the fit function to get a straight line that crosses the point (xo,y0) Commented Mar 12, 2018 at 13:12

 ClearAll["Global*"]

range = {{0.3389, 0.44079999999999997}, {0.3389,
0.4415}, {0.3389, 0.4422}, {0.3389,
0.44289999999999996}, {0.3396, 0.4436}, {0.34099999999999997,
0.4443}, {0.3417, 0.44499999999999995}, {0.34309999999999996,
0.4457}, {0.3438, 0.44639999999999996}, {0.3452,
0.4471}, {0.3459, 0.4478}, {0.34659999999999996,
0.44849999999999995}, {0.348, 0.4492}, {0.3487,
0.44989999999999997}, {0.35009999999999997, 0.4506}, {0.3508,
0.4513}, {0.35219999999999996, 0.45199999999999996}, {0.3529,
0.4527}, {0.3529, 0.45339999999999997}, {0.3529,
0.45409999999999995}, {0.3529, 0.4548}};
{x, y} = Transpose@range;
drop = Take[range, {5, -5}];
x0 = 0.3459;
y0 = 0.4478;

model[t_] := m (t - x0) + y0

fit = FindFit[drop, model[t], m, t]


{m -> 0.6875}

pnew =
Plot[model[t] /. fit, {t, .335, .35}, PlotStyle -> {Black}]

• Thank you so much!! Do you have an idea how to use that for quadratic fit? Commented Mar 12, 2018 at 13:57
• Fit[drop, {1, t,t^2}, t]` I assume all coefficient are unknown. Commented Mar 12, 2018 at 16:50