0
$\begingroup$

I have this code, totally functional

$Assumptions = h > 0; 
p4[x_, h_] := x^4/24 + h*x^3/9 + h^2*x^2/12 - h^4/72; 
q4[x_, h_] := x^4/24 - h*x^3/9 + h^2*x^2/12 - h^4/72
Flatten@Table[{D[p4[x, 3], {x, n}], D[q4[x, 3], {x, n}]}, {n, 0, 3}]

But when I try to plot all these functions together I try to use the code

Plot[Flatten@Table[{D[p4[x, 3], {x, n}], D[q4[x, 3], {x, n}]}, {n, 0, 3}], {x, -3, 3}, PlotLegends -> "Expressions"]

for some reason it doesnt work. Probably this is a silly mistake but I cant see how to solve it. Some help will be appreciated, thank you.

$\endgroup$
2
  • 2
    $\begingroup$ Use Evaluate inside the plot. Plot[Evaluate@ Flatten@Table[{D[p4[x, 3], {x, n}], D[q4[x, 3], {x, n}]}, {n, 0, 3}], {x, -3, 3}, PlotLegends -> "Expressions"] $\endgroup$ – Anjan Kumar Mar 6 '17 at 4:57
  • 1
    $\begingroup$ Another option that works: Plot[#, {x, -3, 3}, PlotLegends -> "Expressions"] & @ Flatten@Table[{D[p4[x, 3], {x, n}], D[q4[x, 3], {x, n}]}, {n, 0, 3}]. Unfortunately my previously preferred form Evaluated -> True doesn't work well with legends. $\endgroup$ – Mr.Wizard Mar 6 '17 at 5:10

Browse other questions tagged or ask your own question.