Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a 2D Plot of 3 functions

Plot[ { f1[x], f2[x], f3[x] }, { x, 8, 18 } ]

where I want f3[x] only plotted for the range [10, 18] instead of [8, 18]. Is that possible?

share|improve this question
1  
add comment

3 Answers 3

up vote 13 down vote accepted

You can use ConditionalExpression (new in version 8) e.g.

Plot[{f1[x], f2[x], ConditionalExpression[f3[x], x > 10]}, {x, 8, 18}]

For example, let's define :

f1[x_] := -4/5 Sin[x]
f2[x_] := Sin[2 x]^2 - 1/2
f3[x_] := Sin[3 x]^5

now

Plot[{ f1[x], f2[x], ConditionalExpression[f3[x], x > 10]}, {x, 8, 18},
       PlotStyle -> {Thick, Thick, Thickness[0.007]}]

enter image description here

The thickest curve is the graph of of f3 in the expected region though f3 is defined for all real (even complex) numbers.

share|improve this answer
    
Perfect. Thanks a bunch. –  stevenvh Jun 20 '12 at 9:55
2  
Alternatively, there's Plot[{f1[x], f2[x], Piecewise[{{f3[x], x > 10}}, Indeterminate]}, {x, 8, 18}]. –  J. M. Jun 20 '12 at 10:49
    
@stevenvh I'm glad I could help. –  Artes Jun 20 '12 at 12:01
    
@J.M. that version also works on v7 whereas ConditionalExpression does not. Please post that as an answer, or I shall. –  Mr.Wizard Jun 20 '12 at 17:43
add comment

At Mr. Wizard's urging: Plot[{f1[x], f2[x], Piecewise[{{f3[x], x > 10}}, Indeterminate]}, {x, 8, 18}] works nicely as an alternative to Artes's answer.

share|improve this answer
add comment

A solution using individual plots combined using Show.

f1[x_] := 1/4 Sin[x]
f2[x_] := 1/2 Sin[2 x]^2
f3[x_] := Sin[3 x]^3

Define a function to plot some functions over some ranges:

Attributes@plotFuncs = {HoldFirst};
plotFuncs[{funcs_, ranges_, opts_}] := 
 Show[Block[Evaluate@Union@ranges[[All, 1]], 
   MapThread[
    Plot[#1[First@#2], #2, #3] &, {funcs, ranges, 
     opts}]], PlotRange -> All]

Plot the three functions:

plotFuncs[{{f1, f2, f3}, {{x, 8, 18}, {y, 8, 18}, {x, 10, 18}}, 
{PlotStyle -> Red, PlotStyle -> Blue, PlotStyle -> Darker@Green}}]

Mathematica graphics

share|improve this answer
    
Thanks for your answer. I'm a beginner at Mathematica, and accepted Artes' answer because it's easier to understand. But thanks again. –  stevenvh Jun 20 '12 at 16:21
    
#@stevenvh No problem, glad you got the answer you needed :) –  image_doctor Jun 20 '12 at 16:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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