I am new to Mathematica and was experimenting with a simply problem of plotting a tangent to a curve and being able to move the point at which the tangent is drawn using Manipulate
. When I run the following, the cell flickers a lot and it also seems to consume a lot of CPU? Is there a way to avoid this?
Manipulate[
Module[{f, x, y, dx, dy},
dx = dy = 1;
f[x_] := x^2;
tangent[x_, y_] := {{x - dx, y - f'[x] dy}, {x + dx, y + f'[x] dy}};
g = Graphics[Line @ tangent[x0, f[x0]], PlotRange -> {{-5, 5}, {-5, 5}}];
p = Plot[f[x], {x, -5, 5}];
Show[p, g]],
{{x0, 2}, -4, 4}]
Comments
Post a Comment