MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A quick question regarding expectation rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63896] Re: [mg63878] A quick question regarding expectation rules
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 21 Jan 2006 01:50:42 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

r={e[1]:>1,
      e[x_+y_]:>e[x]+e[y],
      e[a_?(NumericQ[#]||AtomQ[#]&&
                      MemberQ[Attributes[#],Constant]&)*
            x_.]:>a*e[x],
      e[e[x_]]:>e[x]};

Clear[a,b,x,y];

SetAttributes[{a,b}, Constant]

{e[f[x]],e[a*x],e[b+f[x]],e[3*a+6*e[b*y]]}//.r

{e[f[x]], a*e[x], b + e[f[x]], 3*a + 6*b*e[y]}


Bob Hanlon

> 
> From: "Mark Morrissey" <mmorriss at ou.edu>
To: mathgroup at smc.vnet.net
> Subject: [mg63896] [mg63878] A quick question regarding expectation rules
> 
> 
> Hi Folks - A couple of months ago a lot of you helped me out with 
designing
> a set of rules to apply to expectation operator given 'variables' and
> 'constants'. Below is a set of rules that work quite well.
> 
>  
> 
> However, the rules below expect 'x' or any one single default variable.  How
> might one go about adjusting these rules so that the variables 'x, y, and z'
> (i.e. multiple variables) can be accounted for?
> 
>  
> 
> For example:  E[a x + b y] //. rules[?]= a E[x] + b E[y]  ???
> 
>  
> 
> PLEASE note that I'm using a double stuck 'E' in the notebook (not to be
> confused with the exponential function)
> 
>  
> 
> What I have now:
> 
>  
> 
> (* Expectation Rules*)
> 
> (* x, y, z, are assumed to be random variables and a, b, c are assumed to
> constants *)
> 
> Clear[E,rules];
> 
> rules[x_Symbol:x] := {
> 
>       E[expr_?(FreeQ[#,x]&)] |expr,
> 
>       E[expr1_?(FreeQ[#,x]&) expr2_?(!FreeQ[#,x]&)]|
> 
>         expr1 * E[expr2],
> 
>       E[expr1_?(FreeQ[#,x]&)+expr2_?(!FreeQ[#,x]&)]|expr1+ E[expr2],
> E[E[expr_?(!FreeQ[#,x]&)]]|  E[expr] 
> 
>       };
> 
>  
> 
>  
> 
> In[1]:{E[f[ x]],E[a x], E[b + f[x]], E[a + E[b y]],E[a + E[b y]]} //.
> rules[]  (* using the default {rules[x],rules[y]} where  'x' or 'y' are
> assumed to be variables *)
> 
>  
> 
>  
> 
> Out[1] {E[f[x]],a E[x],b+E[f[x]],a+b y,a+b y}
> 
>  
> 
> Thank you very much.
> 
>  
> 
> Regards - Mark
> 
>  
> 
> Mark Morrissey
> 
> Associate Professor, Meteorology
> 
> University of Oklahoma
> 
> EVAC, 3200 Marshall Ave., Suite 150
> 
> Norman, Oklahoma
> 
> 
> 


  • Prev by Date: Re: NDSolve useless?
  • Next by Date: Re: Re: Problem plotting high-order Laguerre polynomials
  • Previous by thread: Re: A quick question regarding expectation rules
  • Next by thread: Re: Format menu problem