Re: Re: Write an expression in a specific form
- To: mathgroup at smc.vnet.net
- Subject: [mg108072] Re: [mg108014] Re: [mg107952] Write an expression in a specific form
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sun, 7 Mar 2010 05:10:35 -0500 (EST)
- References: <4977982.1267699026953.JavaMail.root@n11>
- Reply-to: drmajorbob at yahoo.com
OK, here's a simple solution: g[m_, s_, x_] = PDF[NormalDistribution[m, s]][x] E^(-((-m + x)^2/(2 s^2)))/(Sqrt[2 \[Pi]] s) c = Integrate[g[m1, s1, x] g[m2, s2, x], {x, -Infinity, Infinity}, Assumptions -> {s1 > 0, s2 > 0}] E^(-((m1 - m2)^2/(2 (s1^2 + s2^2))))/(Sqrt[2 \[Pi]] Sqrt[s1^2 + s2^2]) Checking that we have a PDF: Integrate[1/c g[m1, s1, x] g[m2, s2, x], {x, -Infinity, Infinity}, Assumptions -> {s1 > 0, s2 > 0}] 1 If that's the PDF, here's the mean: m = Integrate[x/c g[m1, s1, x] g[m2, s2, x], {x, -Infinity, Infinity}, Assumptions -> {s1 > 0, s2 > 0}] (m2 s1^2 + m1 s2^2)/(s1^2 + s2^2) And here's the standard deviation: s = Sqrt@Integrate[(x - m)^2/c g[m1, s1, x] g[m2, s2, x], {x, -Infinity, Infinity}, Assumptions -> {s1 > 0, s2 > 0}] Sqrt[(s1^2 s2^2)/(s1^2 + s2^2)] But can we verify it? 1/c g[m1, s1, x] g[m2, s2, x] - g[m, s, x] // Simplify (E^(-((m2 s1^2 + m1 s2^2 - (s1^2 + s2^2) x)^2/( 2 s1^2 s2^2 (s1^2 + s2^2)))) (-s1 s2 + Sqrt[(s1^2 s2^2)/(s1^2 + s2^2)] Sqrt[s1^2 + s2^2]))/(Sqrt[ 2 \[Pi]] s1 s2 Sqrt[(s1^2 s2^2)/(s1^2 + s2^2)]) That needs to be zero for all x, and that's true if and only if: -s1 s2 + Sqrt[(s1^2 s2^2)/(s1^2 + s2^2)] Sqrt[s1^2 + s2^2] == 0 That's a condition on s1 and s2 alone... and it's an easy one: -s1 s2 + Sqrt[(s1^2 s2^2)/(s1^2 + s2^2)] Sqrt[ s1^2 + s2^2] // PowerExpand 0 Done. Bobby On Fri, 05 Mar 2010 03:33:11 -0600, David Park <djmpark at comcast.net> wrote: > 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 > > > > -- DrMajorBob at yahoo.com