2
$\begingroup$

The manipulate function in Mathematica allows the users to adjust the values of the parameters in a graphical way. How do I plot multiple functions in a same graph and also I can use manipulate at the same time?

Manipulate[
 Row[{
   Plot[f1(x+n)], {x, 
     0.0001, 1}, PlotRange -> {-10, 10}],
   Plot[f2(x+n)], {x, 
     0.0001, 1}, PlotRange -> {-10, 10}]}],
   {n, 1, 10}]

with give two independent plots with single curve in each. How should I do multiple curve in a same plot?

$\endgroup$

2 Answers 2

1
$\begingroup$

Like this?

f1[x_] := x^2;
f2[x_] := x^4;
Manipulate[
 Plot[{f1[x + n], f2[x + n]}, {x, 0.0001, 1}, PlotRange->{-10, 10}],
 {n, 1, 10}]

The documentation for Plot shows an example of doing exactly this on the second line. Plot

$\endgroup$
2
  • $\begingroup$ and how to indicate which is which? $\endgroup$
    – user3222184
    Jul 14, 2014 at 1:22
  • $\begingroup$ You could try adding ,PlotLegends->LineLegend["Expressions"] after your PlotRange, but I tend to see the more you have to fiddle with your plot to make it look like you think it must the more grief you will have. And I don't even try to help with that. $\endgroup$
    – Bill
    Jul 14, 2014 at 7:45
1
$\begingroup$

Using Bill's answer but adding Epilog[] for labeling, try

f1[x_] := x^2;
f2[x_] := x^4;
Manipulate[
 Plot[{f1[x + n], f2[x + n]}, {x, 0.0001, 1}, 
  PlotStyle -> {Red, Blue}, PlotRange -> {-10, 10}, Epilog -> {
    (Text[
      Style["f1", FontFamily -> "Times New Roman", FontSize -> 10, 
       Red], {.6, f1[n + .6] + .6}]),
    (Text[
      Style["f2", FontFamily -> "Times New Roman", FontSize -> 10, 
       Blue], {.6, f2[n + .6] + .6}])
    }], {n, 1, 10}]

enter image description here

$\endgroup$

Your Answer

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

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