RE: Formal operations with vectors and scalars
- To: mathgroup at smc.vnet.net
- Subject: [mg70245] RE: [mg70226] Formal operations with vectors and scalars
- From: "David Park" <djmp at earthlink.net>
- Date: Mon, 9 Oct 2006 01:56:00 -0400 (EDT)
Hello WOlfgang, This is the way I would do it. First I would use the following routine that is actually part of Tensorial. LinearBreakout::usage = "LinearBreakout[f1, f2,...][v1, v2,...][expr] will break out the linear \ terms of any expressions within expr that have heads matching the patterns fi \ over variables matching the patterns vj. Example:\n f[a x + b \ y]//LinearBreakout[f][x,y] -> a f[x] + b f[y]"; LinearBreakout[f__][vars__][expr_] := expr //. {(g : Alternatives @@ {f})[p1___, a_ + b__, p2___] :> g[p1, a, p2] + g[p1, Plus[b], p2], (g : Alternatives @@ {f})[p1___, a_ b : Alternatives @@ {vars}, p2___] :> a g[p1, b, p2]} Then here is your derivation all annotated. Just copy and evaluate. Print["Reflection condition for incident ray r and surface normal n"] eqn[1] = n.(a + r) == 0 Print["Represent the reflected ray as a linear combination of the incident \ ray and the surface normal"] eqn[2] = r == A a + B n Print["Substitute the reflected ray in the reflection condition"] eqn[1] /. Rule @@ eqn[2] Print["Breakout the dot product"] %% // LinearBreakout[Dot][a, n] Print["Use ", n.n -> 1, ", and solve for B"] %% /. n.n -> 1 Bsol = Part[Solve[%, B], 1, 1] Print["Substitute in eqn[2]"] eqn[3] = eqn[2] /. Bsol Print["Normalize the reflected ray vector"] r.r == 1 % /. Rule @@ eqn[3] Print["Breakout the dot product, use fact that n and a are unit vectors and \ use symmetry of dot product"] %% // LinearBreakout[Dot][a, n] % /. {n.n -> 1, a.a -> 1, a.n -> n.a} Asols = Solve[%, A] Print["Pick the positive solution for A and substitute in eqn[2]"] eqn[2] /. Bsol /. Part[Asols, 2] // FrameBox // DisplayForm For learning and teaching there are great advantages in doing derivations this way, i.e., doing everything by evaluation. First, you or the student have to gather together the actual rules and definitions that are necessary in the derivation and apply them at the right points. Second, by doing things by calculation the chance for typos and errors is very much lessened. I also think that seeing derivations or proofs as a series of 'actions' is much easier to understand than seeing a set of static expressions on a printed page. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Dr. Wolfgang Hintze [mailto:weh at snafu.de] To: mathgroup at smc.vnet.net Hello group, I'm trying - unsuccessfully - to derive formally simple relations with vectors and scalars using Mathematica. As an example consider the reflexion of a ray of light with initial direction av (unit vector) from a surface at a point with a normal unit vector nv. As ist well known the reflected (unit) vector rv will be given by rv = av - 2 nv (av.nv) where av.nv is the scalar product of av and nv. My question is: how do I derive this relation using Mathematica? (Sorry for bothering you with the derivation, but I need this exposition to show the points where I have difficulties.) With pencil and paper I would start by writing rv as a linaer combination of av and nv, using two scalar constants A and B to be determined, i.e. (1) rv = A av + B nv Now the condition of reflexion can be written (2) nv.(av+rv) = 0 Using (1) to replace rv this reads (remembering also that (nv.nv) = 1) (2') 0 = (nv.av) + A (nv.av) + B Solving for B gives B = - (nv.av) (1+A). Putting this into (1) leads to (1') rv = A av - nv (nv.av) (1+A) Squaring this should give 1: rv.rv = 1 = A^2 + (nv.av)^2 (1+A)^2 - 2 A (1+A) (nv.av)^2 = A^2 + (nv.av)^2 ( 1 + A^2 + 2 A -2 A - 2 A^2) = A^2 + (nv.av)^2 (1-A^2) = A^2 (1-(nv.av)^2) + (nv.av)^2 or (1-(nv.av)^2) = A^2 (1-(nv.av)^2) giving A = +- 1 in view of (1') we must select the positive sign. Now, how would I proceed in Mathematica? I would write down (1) as well, would next impose (2). Here the first difficulty appears because Mathematica does not know that av, nv and rv designate vectors, the dot product is not distributed, the scalars A and B are not recognized either. I tried Simplify with conditions but this didn't help... Can you please outline how to tackle this derivation with Mathematica? Many thanks in advance. Wolfgang