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 want to define a piecewise function, which has two arguments, one of which is a function of the other's piecewise argument. I am giving an example

X0 = 1.7635;
X1 = 4.4855;
γ[En_] := En/0.13957
β[En_] := Sqrt[γ[En]^2 - 1]/γ[En]
X[En_] := Log[10, β[En]*γ[En]]
f[En_, Evaluate[X[En_] _]] :=Piecewise[{{0, X[En] < X0}, {4*X[En], X[En] > X0}}]
PLot[f[En, Evaluate[X[En]]], {En, 0.001, 1000}]

Is it possible?

share|improve this question
1  
Why not defining f[En_] :=Piecewise[{{0, X[En] < X0}, {4, X[En] > X0}}] ? –  b.gatessucks Sep 14 '12 at 7:21
    
If I use that it doesn't make any plot at all. I just get PLot[\[Piecewise] { {0, Log[1. Sqrt[-1 + 51.3353 En^2]]/Log[10] < 1.7635}, {((4 Log[1. Sqrt[-1 + 51.3353 En^2]])/Log[10]), Log[1. Sqrt[-1 + 51.3353 En^2]]/Log[10] > 1.7635}, {0, \!\(\* TagBox["True", "PiecewiseDefault", AutoDelete->False, DeletionWarning->True]\)} }, {En, 0.001, 1000}] –  Thanos Sep 14 '12 at 8:16
    
Are you really using PLot ? It should be Plot (L not capitalized). –  b.gatessucks Sep 14 '12 at 8:26
    
That is so true... I realised that a couple of hours ago... Thank's for your help! –  Thanos Sep 14 '12 at 14:50

2 Answers 2

up vote 2 down vote accepted

In short, yes it is possible. In your setup \[Beta][En] is complex for En < 0.13957.

I'd do :

f[En_] := Piecewise[{{0, X[En] <= X0}, {4, X[En] > X0}}]

minEn=FindRoot[\[Gamma][En]^2 - 1 == 0, {En, 0.1}][[1,2]]
(* 0.13957 *)

Plot[{X0, X[En], f[En]}, {En, minEn, 10}, PlotRange -> All, 
  PlotStyle -> {Automatic, Automatic, {Red, Thick}}]

plot

share|improve this answer
    
The non real part, is indeed a problem...Actually 0.13957 is a particle's mass. This computation formula doesn't allow me to go bellow that energy, but OK this forum is not about that. Sorry! Thank you very much for your answer! –  Thanos Sep 14 '12 at 8:28

Not really sure if this is what you want to achieve, but anyway

X0 = 1.7635;
X1 = 4.4855;
γ[En_] := En/0.13957
β[En_] := Sqrt[γ[En]^2 - 1]/γ[En]
X[En_] := Log[10, β[En]*γ[En]]
f[En_?NumericQ, h_?NumericQ] := Piecewise[{{0, h < X0}, {4, h > X0}}]
Plot[f[En, X[En]], {En, 1, 10}, Exclusions -> None]

Mathematica graphics

share|improve this answer
    
I can't understand how you relate h with X[En] –  Thanos Sep 14 '12 at 8:30
    
Oh...I just got it! You give f two arguments and when plotting you use X[En] as the second argument! Nice! Thank you very much! –  Thanos Sep 14 '12 at 8:32

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.