# dharmatech/Symbolism

### Subversion checkout URL

You can clone with
or
.

Add test version of PSE Example 4.3

commit 9858bf132865be97e0d686faebeed3c444733b17 1 parent 4206cdd
authored
6 PSE Example 4.3 The Long-Jump/Program.cs
 @@ -28,11 +28,9 @@ static void Main(string[] args) var thA = new Symbol("thA"); // angle at point A var vA = new Symbol("vA"); // velocity at point A - // var g = new DoubleFloat(9.8); + var g = new Symbol("g"); // magnitude of gravity - var g = new Symbol("g"); - - var _g = new Point(new Integer(0), -g); + var _g = new Point(new Integer(0), -g); // gravity vector // An Obj representing the object at A:
3  Symbolism/Program.cs
 @@ -80,6 +80,9 @@ public abstract class MathObject #endregion ////////////////////////////////////////////////////////////////////// + //public static Equation operator ==(MathObject a, double b) + //{ return new Equation(a, new DoubleFloat(b)); } + public static Equation operator ==(MathObject a, MathObject b) { return new Equation(a, b); }
75 Tests/Program.cs
 @@ -4,6 +4,7 @@ using System.Text; using Symbolism; +using Physics; namespace Tests { @@ -11,6 +12,11 @@ class Program { static void Main(string[] args) { + Action AssertIsTrue = (eq) => + { + if (!eq) Console.WriteLine(eq.ToString()); + }; + { var x = new Symbol("x"); var y = new Symbol("y"); @@ -18,11 +24,6 @@ static void Main(string[] args) Func Int = (n) => new Integer(n); - Action AssertIsTrue = (eq) => - { - if (!eq) Console.WriteLine(eq.ToString()); - }; - AssertIsTrue(x + x == 2 * x); AssertIsTrue(x + x == 2 * x); @@ -141,10 +142,72 @@ static void Main(string[] args) AssertIsTrue(x * 1 == x); } + { + // PSE Example 4.3 + + var thA = new Symbol("thA"); // angle at point A + var vA = new Symbol("vA"); // velocity at point A + + var g = new Symbol("g"); // magnitude of gravity + + var _g = new Point(new Integer(0), -g); // gravity vector + + var objA = + new Obj() + { + position = new Point(0, 0), + velocity = Point.FromAngle(thA, vA), + acceleration = _g, + time = new Integer(0) + }; + + var objB = + new Obj() + { + position = new Point(), + velocity = new Point(objA.velocity.x, new Integer(0)), + acceleration = _g + }; + + var timeB = Calc.Time(objA, objB); + var timeC = timeB * 2; + + objB = objA.AtTime(timeB); + var objC = objA.AtTime(timeC); + + //Console.WriteLine("How far does he dump in the horizontal direction?"); + + AssertIsTrue(objC.position.x == 2 * Trig.Cos(thA) * Trig.Sin(thA) * (vA ^ 2) / g); + + //Console.WriteLine("What is the maximum height reached?"); + + AssertIsTrue(objB.position.y == (Trig.Sin(thA) ^ 2) * (vA ^ 2) / 2 / g); + + // Console.WriteLine("Distance jumped: "); + + AssertIsTrue( + objC.position.x + .Substitute(thA, Trig.ToRadians(20)) + .Substitute(g, new DoubleFloat(9.8)) + .Substitute(Trig.Pi, new DoubleFloat(3.14159)) + .Substitute(vA, new Integer(11)) + == + new DoubleFloat(7.9364536850196412)); + + //Console.WriteLine("Maximum height reached: "); + + AssertIsTrue( + objB.position.y + .Substitute(g, new DoubleFloat(9.8)) + .Substitute(thA, Trig.ToRadians(20)) + .Substitute(Trig.Pi, new DoubleFloat(3.14159)) + .Substitute(vA, new Integer(11)) + == + new DoubleFloat(0.72215756424454336)); + } Console.WriteLine("Testing complete"); Console.ReadLine(); - } } }
4 Tests/Tests.csproj
 @@ -47,6 +47,10 @@ + + {73E0C26D-5333-4575-A3E9-5388E975446E} + Physics + {067278C5-2A0F-42DE-838B-855EFB652608} Symbolism