RE: Beginner, plot with multiple rules depending on parameters
- To: mathgroup at smc.vnet.net
- Subject: [mg83788] RE: [mg83739] Beginner, plot with multiple rules depending on parameters
- From: "Jaccard Florian" <Florian.Jaccard at he-arc.ch>
- Date: Fri, 30 Nov 2007 05:27:31 -0500 (EST)
- References: <200711291131.GAA27548@smc.vnet.net>
Hello,
I'm afraid I don't really understand the end of your message...
But I can say that from 5.2 on, it is easier to do what you want using
the Piecewise function. If I remember well, it doesn't exist in the
version 5.0.
If you want your function to be easily derivated, Laplace transformed
and so on, I think the best way to define your function with 5.0 is not
using "/;" , but using UnitStep.
Like this :
f[x_, a_, b_, f1_, f2_] := UnitStep[a - x]*f1 + UnitStep[b - x, x -
a]*f2
Example :
Plot[f[x, 1, 3, x^2, Sin[x]], {x, 0, 5}]
Hope it helps!
Regards
F.Jaccard
-----Message d'origine-----
De=A0: Francesco Mosconi [mailto:mosconi at pd.infn.it]
Envoy=E9=A0: jeudi, 29. novembre 2007 12:32
=C0=A0: mathgroup at smc.vnet.net
Objet=A0: [mg83739] Beginner, plot with multiple rules depending on
parameters
Hello,
I am a beginner user, and I am using Mathematica 5.0 on Windows XP. I
would like to plot a function which is composed by three rules of the
form:
if x < a => F[x] = f1
if a < x < b => F[x] = f2
etc.
The thing is slightly complicated by the fact that the function rules
and the points of junction depend on several parameters and I don't know
how to evaluate them correcly. I wrote the following code:
------------------Mathematica Code--------------------------------
(*
First I clear all the variables, define the standard parameter
substitution, define some constants.
Then I define the functions of g[f],cs[f],ss[f] and sp[f].
Finally I give the rules for the function F[f,s], which is formed by
three parts, depending on the value of s.
*)
ClearAll;Clear[F];Clear[z];
stdpar = {A->50,CC->95,P->40};
kBT = 4.1;
c=kBT CC (2 Pi/3.6)^2;
p=kBT P (2 Pi/3.6)^2;
fc=kBT/A;
g[f_]:=f-Sqrt[f*fc]
cs[f_]:=c*(1-CC/(4 A)*Sqrt[fc/f])
ss[f_]:=FullSimplify[1/cs[f]*Sqrt[2 p g[f]/(1-p/cs[f])]];
sp[f_]=FullSimplify[1/p*Sqrt[2 p g[f]/(1-p/cs[f])]];
F[f_,s_]:=-g[f]+1/2 cs[f] s^2 /;s < s[f]
F[f_,s_]:=FullSimplify[-g[f]/(1-p/cs[f])+Sqrt[2 p g[f]/(1-
p/cs[f])]*s]/;ss[f]<s < sp[f]
F[f_,s_] := 1/2 p s^2 /; s > sp[f]
?F
(*
Here I just want to check that the functions of f evaluate correcly when =
all the standard parameters are substituted.
*)
g[1]/.stdpar
cs[1]/.stdpar
ss[1]/.stdpar
sp[1]/.stdpar
(*
Now I would like to do the same for F, evaluating it for particular
values of f and s
*)
F[1,0.1]/.stdpar
(*
I define the function z[f,s] as minus the derivative of F with respect =
to f
*)
z[f_,s_]=FullSimplify[-D[F[f,s],f]]
(*
And I would like to plot it for different values of f and s.
*)
Plot[Evaluate[Table[z[f,s],{
f,0.02,1,0.1}]/.stdpar],{s,0,0.1},PlotRange\[Rule]{-1,1}]
------------------Mathematica Code--------------------------------
I must have got sumething wrong because the function F[f,s] does not
evaluate to a number even when the /.stdpar rule is applied.
Can anyone suggest a solution?
Thank you very much
Francesco
- References:
- Beginner, plot with multiple rules depending on parameters
- From: Francesco Mosconi <mosconi@pd.infn.it>
- Beginner, plot with multiple rules depending on parameters