Skip to content

Instantly share code, notes, and snippets.

@kenkangxgwe
Created February 5, 2017 02:54
Show Gist options
  • Save kenkangxgwe/1950294181066c1fc9d2753f3db68930 to your computer and use it in GitHub Desktop.
Save kenkangxgwe/1950294181066c1fc9d2753f3db68930 to your computer and use it in GitHub Desktop.
Using Least Square Method for a X-Y 2D array.
(* ::Package:: *)
Targetdir1 = "%Yourdir%\\*.txt"
(*For the table having two demensions.*)
Data=Import[Targetdir1,"Table"];
Model = LinearModelFit[Data, x, x]
Show[ListPlot[Data, AxesOrigin -> {0, 0}, AxesLabel -> {"x", "y"}],
Plot[Normal[Model], {x, First[First[Data]], First[Last[Data]]}]]
Model["ParameterTable"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment