# Function returned from module doesn't work [closed]

I have a sequence of steps that work in the main notebook:

MakeSlope=Function[x,Evaluate[Function[n,n*x]]]

In[708]:= f1x0 = 3.4
f1der[f1x0]
f1x0s = MakeSlope[f1der[f1x0]];
f1x0s[x]
f1x0ydif = f1[f1x0] - f1x0s[f1x0]
f1x0t = f1x0s[x] + f1x0ydif

Out[708]= Function[x, 2 x]

Out[710]= 3.4

Out[711]= 6.8

Out[713]= 6.8 x

Out[714]= -11.56

Out[715]= -11.56 + 6.8 x


But inside a Module,

GetTangent[f_,x0_]:=Module[{fder,der,x,s,ydif,t},
fder=Function[x,Evaluate[D[f[x],x]]];
der=fder[x0];
s=MakeSlope[der];
ydif=f[x0]-s[x0];
t=s[x]+ydif;
t
];


I get in return a function which seems ok mathematically, but with an appended $code: In[705]:= f1t = GetTangent[Function[x, x^2], 2] Out[706]= -4 + 4 x$98923


When I try to plot it, I get an empty plot.

Any ideas as to what might be wrong?

• Ok. I have added MakeSlope to the beginning of the code. – pedroos Jan 19 '19 at 15:54
• As written x is locally scoped to Module so that result is as it should be. Might instead make it an explicit argument to GetTangent. – Daniel Lichtblau Jan 19 '19 at 16:07
• Read up on how Module works reference.wolfram.com/language/tutorial/HowModulesWork.html That should explain why you get x$nnn. Second, what are you doing to plot it? Surely Plot[-4 + 4 x$98923, {x\$98923,x_min, x_max} ] works? – void life Jan 19 '19 at 16:09
• I was just plotting the function directly: Plot[GetTangent[Function[x, x^2], 2], {x, -10, 10}], but I got an empty plot. @DanielLichtblau's comment solved it. – pedroos Jan 19 '19 at 16:12