Clear[var, expr, blah, g, derivatives];
var = Input[“Type a variable, such as x, in this window.”];
expr = Input[ “Type an expression to be differentiated in the variable you just typed in the last window.”];
g[blah_] = expr /. {var → blah};
derivatives := {g[var], g’[var]}
Plot[{derivatives}, {x, -3, 5}, {PlotLabel → “A function and its Derivative”,
PlotLabel → Automatic, PlotRange → All}]
All I’m trying to do is label my curves on the graph as whatever that curve is, such as the function “2x^2” and then I want the derivative to be labeled also, so “4x”..And I mean labeled on the actual curves, not the legend on the side (I know how to do that).. It appears my PlotLabel and PlotRange aren’t doing anything at all. Do I have to be more specific in PlotLabel? I thought of extracting each element such as derivative[[1]] for the function and derivative[[2]] for the actual derivative and then naming those somehow… I feel like I’m missing something easy.
var = Input["Type a variable, such as x, in this window."];
expr = Input[
"Type an expression to be differentiated in the variable you just \
typed in the last window."];
g[blah_] = expr /. {var -> blah};
derivatives := {Callout[g[var], "function"],
Callout[g'[var], "derivative"]}
Plot[Evaluate@derivatives, {x, -3, 5},
PlotLabel -> "A function and its Derivative", PlotRange -> 10]
Gianluca,
I got the impression that the original poster wants the curves to be labeld by the functions itself. Not just “function” and “derivative”. So this a simple variation of your solution:
var = Input["Type a variable, such as x, in this window."];
expr = Input[
"Type an expression to be differentiated in the variable you just typed in the last window."];
g[blah_] = expr /. {var -> blah};
derivatives := {Callout[g[var], g[var], Above], Callout[g'[var], g'[var], Above]};
Plot[
Evaluate@derivatives, {x, -3, 5},
PlotLabel -> "A function and its Derivative", PlotRange -> 20
]
Another one. Uses the Plot option PlotLabels. Instead of the function wrappers Callout or Labeled.
var = Input["Type a variable, such as x, in this window."];
expr = Input[
"Type an expression to be differentiated in the variable you just typed in the last window."];
g[blah_] = expr /. var -> blah;
derivatives = {g[var], g'[var]};
Plot[
Evaluate@derivatives, {x, -3, 5},
PlotLabel -> "A function and its Derivative",
PlotLabels -> Placed["Expressions", Above],
PlotRange -> 20
]