1
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ Why not defining f[En_] :=Piecewise[{{0, X[En] < X0}, {4, X[En] > X0}}] ? $\endgroup$ – b.gates.you.know.what Sep 14 '12 at 7:21
  • $\begingroup$ 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}] $\endgroup$ – Thanos Sep 14 '12 at 8:16
  • $\begingroup$ Are you really using PLot ? It should be Plot (L not capitalized). $\endgroup$ – b.gates.you.know.what Sep 14 '12 at 8:26
  • $\begingroup$ That is so true... I realised that a couple of hours ago... Thank's for your help! $\endgroup$ – Thanos Sep 14 '12 at 14:50
2
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – Thanos Sep 14 '12 at 8:28
1
$\begingroup$

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

$\endgroup$
  • $\begingroup$ I can't understand how you relate h with X[En] $\endgroup$ – Thanos Sep 14 '12 at 8:30
  • $\begingroup$ 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! $\endgroup$ – Thanos Sep 14 '12 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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