Skip to content

Instantly share code, notes, and snippets.

@lucainnocenti
Created July 31, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucainnocenti/96c3d6d78c6cc8b8dc3dabfe72ef9aef to your computer and use it in GitHub Desktop.
Save lucainnocenti/96c3d6d78c6cc8b8dc3dabfe72ef9aef to your computer and use it in GitHub Desktop.
linear approximation of function in MMA
xMax = 1.4;
numPartitions = 10; dx = xMax/numPartitions;
pointsAndLines[pts_] := {Point@pts, Line@pts};
fun[x_] := x^2;
Plot[fun@x, {x, 0, xMax},
PlotRange -> All, PlotStyle -> Directive[Thick], Frame -> True,
GridLines -> Automatic,
FrameStyle -> Directive[Black, Thick, Large],
PlotLegends -> "Expressions",
ImageSize -> 500
]~Show~Graphics[{
PointSize@0.02,
pointsAndLines[
Thread@{# dx, Accumulate[dx fun'[(# - 1) dx]]} &@
Table[k, {k, 1, numPartitions}] // Prepend@{0, 0}]
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment