# How to Plot a function that returns multiple values? [duplicate]

I have a function that returns multiple values, like this:

f[x_] := ( (*... something ... *); {y1, y2});


They are computed together, so there's absolutely no sense to split the function to two functions.

Now, I want to plot them both:

Plot[f[a], {a,0,1}]


Oops, the two graphs are drawn with the same style. Explicit style decaration (like PlotStyle->{Red,Green}) doesn't change the situation. The Plot routine doesn't recognize f[a] as two values. This is the main trouble. Well, the documentation has a cure for this:

Plot[Evaluate[f[a]], {a,0,1}]


It's OK... until it turns out that 1) numerical computation of f if slow, and 2) symbolic computation of f is extremely slow. In my case, there is a system of 10 linear equations. And this last expression evaluates f symbolically. Well, of course, I can forbid this by declaring f as f[x_?NumericQ], but then the Evaluate operation becomes totally useless.

Why should I evaluate the whole function symbolically only to ensure that it returns two values? Is there another way to explain this fact to the Plot routine, so it would use different styles for the two graphs?

Well, actually, I know the answer:

Plot[{f[a][], f[a][]}, {a,0,1}]


But it is ugly and wasteful. It performs almost the same computations twice. It makes me feel uncomfortable. May be, there is a better solution?

## marked as duplicate by Mr.Wizard♦Apr 27 '14 at 19:51

• Thank you. Of course, I tried to find someting like this before asking, but I failed. Also, now I see in Related questions an elegant solution with splitstyle here. – colt_browning Apr 27 '14 at 19:55
• Reviewing the answers, Simon's splitstyle method in the second linked question is probably what you want; it's better than my methods in earlier question. – Mr.Wizard Apr 27 '14 at 20:01