0
$\begingroup$

currently I am trying to plot for the Legendre polynomial $P_n(x)$ for $n=0,1,2,3,4$ and $-1 \leq x \leq 1$ .

To plot for it, I wrote the following code:

MyLegendre=Table[[LegendreP[v,x],x],{n,0,4}]; Plot[MyLegendre,{x,-1,1},PlotLabels -> {"v=0", "v=1", "v=2", "v=3", "v=4"}]

However, Mathematica keeps stating that there is an error with my above code. Any help to resolve this problem would be greatly appreciated. Thank you for the help!

$\endgroup$
2
  • 2
    $\begingroup$ MyLegendre = Table[LegendreP[v, x], {v, 0, 4}]; Plot[ MyLegendre // Evaluate, {x, -1, 1}, PlotLabels -> {"v=0", "v=1", "v=2", "v=3", "v=4"}] $\endgroup$
    – cvgmt
    Commented Sep 24, 2020 at 23:32
  • $\begingroup$ Thank you! The code now works perfectly! $\endgroup$
    – Athenian
    Commented Sep 24, 2020 at 23:39

1 Answer 1

2
$\begingroup$
Clear["Global`*"]

You need to reposition the labels

MyLegendre = Table[LegendreP[v, x], {v, 0, 4}]; 
Plot[MyLegendre, {x, -1, 1},
 Frame -> True, 
 PlotLabels -> 
  Placed[{"v=0", "v=1", "v=2", "v=3", "v=4"}, 
    {{Scaled[0.5], Above}, {Scaled[0.385], Above}}]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.