1
$\begingroup$

I want to plot a family of equations for different values of $C$. For example $x^2+y^2=C$. How?

I found out that this doesn't work:

ContourPlot[x^2 + y^2 == C /. C -> Range[0, 5], {x, -10, 10}, {y, -10, 10}]

What will work?

Thanks!

$\endgroup$
2
  • $\begingroup$ What you're looking for is the option Contours -> Range[0, 5]. Get rid of the == C and add that option after the domain specification. $\endgroup$
    – march
    Oct 12, 2015 at 20:19
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ Oct 12, 2015 at 21:53

2 Answers 2

2
$\begingroup$

Try mapping the plotting function over the range of interest. Like this:

Map[ContourPlot[x^2 + y^2 == #, {x, -10, 10}, {y, -10, 10}] & , Range[0, 5]]

or in op form:

ContourPlot[x^2 + y^2 == #, {x, -10, 10}, {y, -10, 10}] &  /@  Range[0, 5]

or all the plots together:

cplots = Map[  ContourPlot[x^2 + y^2 == #, {x, -10, 10}, {y, -10, 10}] & , 
             Range[0, 5]]; 
Show[cplots]

Hope this helps Cheers!

$\endgroup$
1
  • $\begingroup$ @Imre: I tried to answer your question using general functional programming concepts (in this case mapping a function over a range), keeping your code as intact as possible. Assuming that your code reflects your way to think about a problem, chances are that you may be able to apply this solution in different contexts. However, Belisarius' answer below is more idiomatic. (@march's comment also points out the use of Contours -> Range option). $\endgroup$
    – paramecium
    Oct 13, 2015 at 12:46
4
$\begingroup$
ContourPlot[x^2 + y^2, {x, -10, 10}, {y, -10, 10}, 
            Contours -> Range[0, 100, 10], ContourShading -> None]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ @Imre, belisarius: I think this is a better answer. More idiomatic and representative of the gazillion options packed in Wolframatica's high-level functions. $\endgroup$
    – paramecium
    Oct 13, 2015 at 12:40
  • $\begingroup$ @paramecium Thanks. I also believe that. The problem with accepting non-optimal answers is that future users will get those as the "best" method available misguiding them. Anyway that happens a lot here. BTW, I alredy upvoted your answer :) $\endgroup$ Oct 13, 2015 at 15:28

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.