This is my code for playing this kind of stuff
A = {1, 1};
B = {0, -1};
c = {x, 0};
l1 = EuclideanDistance[A, c];
l2 = EuclideanDistance[c, B];
f[x_] := l1/1 + l2/2;
D[f[x], x]
g[x_] := D[f[x], x]
g[1]
Plot[g[x], {x, -20, 20}, PlotRange -> 20 {{-1, 1}, {-1, 1}},
PlotStyle -> Red, AspectRatio -> Automatic, ImageSize -> 400]
To clarify, there seem to be three or four questions, some of which are in the title, some to be inferred from comments or evaluating the code:
- Why are
Abs'[1 - x]
andAbs'[x]
left unevaluated in the output ofD[f[x], x]
? - Why does
g[1]
result in an error "General::ivar
1 is not a valid variable"? - Why does
Plot[...]
generate similarGeneral::ivar
errors? - Why does the
Plot
comes up empty when only the previous two problems are fixed? (It came up blank originally because of the problem withD[...]
.)
Plot
in the function $\endgroup$f[x_] = Block[{Abs = RealAbs}, l1/1 + l2/2]
together with Carl's suggestion ofg = f'
. $\endgroup$