MathGroup Archive 2010

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

Search the Archive

Re: Write an expression in a specific form

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108014] Re: [mg107952] Write an expression in a specific form
  • From: "David Park" <djmpark at comcast.net>
  • Date: Fri, 5 Mar 2010 04:33:11 -0500 (EST)
  • References: <4977982.1267699026953.JavaMail.root@n11>

I suppose that someone will get this with some simple command but, in case
not, here is my somewhat laborious solution using Presentations. I won't
show all the output lines, but just the results. Most of the steps are done
on the argument of Exp. In the final steps I substituted f for Exp to keep
Mathematica from recombining the products, and then put the final answer in
Subexpressions.

Needs["Presentations`Master`"] 

G[m_, s_, x_] := Exp[-((x - m)^2/(2 s^2))]/(s Sqrt[2 \[Pi]]) 

initial = G[m1, s1, x]*G[m2, s2, x] 
Part[initial, 2, 2] 
step1 = CompleteTheSquare[%, x] 
step2 = step1 // MapLevelParts[Simplify, {{1, 2, 3}}] 
rule1 = (expr1 = Part[step2, 2, 1]) -> (expr2 = 
    Factor[Together[expr1]]) 
rule2 = -2 expr2 -> 1/s^2 
step3 = step2 /. rule1 /. rule2 
step4 = MapAt[Simplify, step3, {{2, 3, 1, 1}}] 
rule3 = -Part[step4, 2, 3, 1, 1] -> m 
step5 = step4 /. rule3 
msrules = {rulem = Reverse[rule3], rules2 = Reverse[1/# & /@ rule2], 
  rules = PowerExpand[Sqrt[#]] & /@ rules2} 
(Times @@ f /@ step5)/(2 \[Pi] s1 s2) 
MapAt[FactorOut[Sqrt[2 \[Pi]] s, CreateSubexpression], %, {6}]; 
MapAt[FactorOut[Sqrt[2 \[Pi]] s1 s2/s, CreateSubexpression], %, {5}]; 
final = % /. f -> Exp  

The final answer, with Subexpressions converted to HoldForm:

HoldForm[E^(-((-m + x)^2/(2 s^2)))/(Sqrt[2 \[Pi]] s)] HoldForm[(
  E^(-((m1 - m2)^2/(2 (s1^2 + s2^2)))) s)/(Sqrt[2 \[Pi]] s1 s2)] 

With the rules:

{m -> (m2 s1^2 + m1 s2^2)/(s1^2 + s2^2), 
 s^2 -> (s1^2 s2^2)/(s1^2 + s2^2), s -> (s1 s2)/Sqrt[s1^2 + s2^2]}

This tests that the results are the same

(final // ReleaseSubexpressions[]) /. msrules // Simplify;
initial // ExpandAll // Simplify;
%% == % 
True 


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  


From: Ares Lagae [mailto:ares.lagae at sophia.inria.fr] 

Hi all,

I am a beginner in Mathematica, and I have the following "problem": How can 
I write an expression in a specific form?

For example:

- Define a Gaussian:

G[m_, s_, x_] := (1/(s*Sqrt[2*Pi]))*Exp[-(x - m)^2/(2*s^2)];

- Product of two Gaussians:

G[m1, s1, x] * G[m2, s2, x]

- How can I get Mathematica to write the result in terms of c * G[m_, s_, 
x_]? I.e., get the values for c, m and s.

Thanks,

Ares Lagae





  • Prev by Date: Re: Select Maximum Value
  • Next by Date: Re: clearing denominators and eliminating square roots in *huge*
  • Previous by thread: Re: Re: Write an expression in a specific form
  • Next by thread: Re: Re: Write an expression in a specific form