1
$\begingroup$

This question already has an answer here:

I'd like to plot a few curves in a plot but with different colors, like in this code :

f[x_, a_] = x*Log[x] + (1 - x)*Log[1 - x] - a*x^2 ;
Plot[Table[f[x, a], {a, {0, 1, 2, 3, 4, 5, 6, 7}}], {x, 0.0001, 0.9999}]

But I'm getting all of them in blue !

plot

What can I do ?

$\endgroup$

marked as duplicate by J. M. will be back soon plotting Nov 16 at 18:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Attributes[Plot] shows that Plot has the attribute HoldAll. Evaluate the Table to override the HoldAll. $\endgroup$ – Bob Hanlon Oct 10 at 13:17
  • $\begingroup$ I am certain this is a dupe... $\endgroup$ – J. M. will be back soon Nov 16 at 17:57
  • $\begingroup$ @J.M. is (1731) good enough? $\endgroup$ – Mr.Wizard Nov 16 at 18:13
  • $\begingroup$ @Mr.Wizard, my memory is going really bad as of late; I should have known we've made it an FAQ. :) $\endgroup$ – J. M. will be back soon Nov 16 at 18:18
  • $\begingroup$ @J.M. I know the feeling, believe me. $\endgroup$ – Mr.Wizard Nov 16 at 18:20
3
$\begingroup$

One possible way

 f[x_,a_]=x*Log[x]+(1-x)*Log[1-x]-a*x^2;
 Plot[Evaluate@Table[f[x, a], {a, {0, 1, 2, 3, 4, 5, 6, 7}}], {x, 0.0001, 0.9999}]

Mathematica graphics

I would also consider changing your definition from f[x_,a_]=x*Log[x]+(1-x)*Log[1-x]-a*x^2; to f[x_,a_]:=x*Log[x]+(1-x)*Log[1-x]-a*x^2;

$\endgroup$

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