# dharmatech/Symbolism

Factor out physics example. Physics is now a library.

1 parent 82bf8fa commit 46688b7b4cca8667d214cedc7ca072b7b8dc2422 committed Jan 19, 2013
 @@ -0,0 +1,67 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {51C1B8ED-EDB7-443F-BE76-58A881EEFB20} + Exe + Properties + PSE_Example_4._3_The_Long_Jump + PSE Example 4.3 The Long-Jump + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + {73E0C26D-5333-4575-A3E9-5388E975446E} + Physics + + + {067278C5-2A0F-42DE-838B-855EFB652608} + Symbolism + + + + +
 @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Symbolism; +using Physics; + +namespace PSE_Example_4._3_The_Long_Jump +{ + class Program + { + static void Main(string[] args) + { + // A long-jumper leaves the ground at an angle of 20.0° above + // the horizontal and at a speed of 11.0 m/s. + // (a) How far does he jump in the horizontal direction? + // (Assume his motion is equivalent to that of a particle.) + // (b) What is the maximum height reached? + + // For the purposes of solving the problem, let's take + // point A as the initial position + // point B as the peak position + // point C as the final position. + + // First we'll get the answer in a symbolic form. + + 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"); + + var _g = new Point(new Integer(0), -g); + + // An Obj representing the object at A: + + 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?"); + Console.WriteLine(objC.position.x); + + Console.WriteLine(); + + Console.WriteLine("What is the maximum height reached?"); + Console.WriteLine(objB.position.y); + + Console.WriteLine(); + + Console.WriteLine("Now for the numerical solutions:"); + + Console.WriteLine(); + + Console.WriteLine("Distance jumped: "); + + Console.WriteLine( + 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)) + ); + + Console.WriteLine(); + + Console.WriteLine("Maximum height reached: "); + + Console.WriteLine( + 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)) + ); + + Console.ReadLine(); + + } + } +}
 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PSE Example 4.3 The Long-Jump")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PSE Example 4.3 The Long-Jump")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7f873ffc-5db9-40a5-a5f9-ee0e7e76734a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]
 @@ -6,7 +6,7 @@ 8.0.30703 2.0 {73E0C26D-5333-4575-A3E9-5388E975446E} - Exe + Library Properties Physics Physics @@ -33,6 +33,9 @@ prompt 4 + + +
 @@ -7,7 +7,7 @@ namespace Physics { - static class Trig + public static class Trig { public static Symbol Pi = new Symbol("Pi"); @@ -26,7 +26,7 @@ public static MathObject Cos(MathObject arg) { return new Symbolism.Cos(arg).Simplify(); } } - class Point + public class Point { public MathObject x; public MathObject y; @@ -55,7 +55,7 @@ public override string ToString() { return new Point(a.x / b, a.y / b); } } - class Obj + public class Obj { public Point position; public Point velocity; @@ -90,7 +90,7 @@ public Obj AtTime(MathObject t) } } - static class Calc + public static class Calc { public static MathObject Time(Obj a, Obj b) { @@ -111,95 +111,4 @@ public static MathObject Time(Obj a, Obj b) throw new Exception(); } } - - class Program - { - static void Main(string[] args) - { - // A long-jumper leaves the ground at an angle of 20.0° above - // the horizontal and at a speed of 11.0 m/s. - // (a) How far does he jump in the horizontal direction? - // (Assume his motion is equivalent to that of a particle.) - // (b) What is the maximum height reached? - - // For the purposes of solving the problem, let's take - // point A as the initial position - // point B as the peak position - // point C as the final position. - - // First we'll get the answer in a symbolic form. - - 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"); - - var _g = new Point(new Integer(0), -g); - - // An Obj representing the object at A: - - 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?"); - Console.WriteLine(objC.position.x); - - Console.WriteLine(); - - Console.WriteLine("What is the maximum height reached?"); - Console.WriteLine(objB.position.y); - - Console.WriteLine(); - - Console.WriteLine("Now for the numerical solutions:"); - - Console.WriteLine(); - - Console.WriteLine("Distance jumped: "); - - Console.WriteLine( - 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)) - ); - - Console.WriteLine(); - - Console.WriteLine("Maximum height reached: "); - - Console.WriteLine( - 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)) - ); - - Console.ReadLine(); - } - } }
 @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Physics", "Physics\Physics.csproj", "{73E0C26D-5333-4575-A3E9-5388E975446E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSE Example 4.3 The Long-Jump", "PSE Example 4.3 The Long-Jump\PSE Example 4.3 The Long-Jump.csproj", "{51C1B8ED-EDB7-443F-BE76-58A881EEFB20}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -25,6 +27,10 @@ Global {73E0C26D-5333-4575-A3E9-5388E975446E}.Debug|x86.Build.0 = Debug|x86 {73E0C26D-5333-4575-A3E9-5388E975446E}.Release|x86.ActiveCfg = Release|x86 {73E0C26D-5333-4575-A3E9-5388E975446E}.Release|x86.Build.0 = Release|x86 + {51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Debug|x86.ActiveCfg = Debug|x86 + {51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Debug|x86.Build.0 = Debug|x86 + {51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Release|x86.ActiveCfg = Release|x86 + {51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE