Permalink
Browse files

Add PSE 5E Example 4.5

  • Loading branch information...
1 parent 1a4fa48 commit a9ce12fb4c671006347be81669af3e8f122d64ea @dharmatech committed Mar 8, 2013
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{98A9D4E4-2AD1-4CC9-8697-C25097CA7420}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>PSE_5E_Example_4._5_Thats_Quite_An_Arm</RootNamespace>
+ <AssemblyName>PSE 5E Example 4.5 Thats Quite An Arm</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Physics\Physics.csproj">
+ <Project>{73E0C26D-5333-4575-A3E9-5388E975446E}</Project>
+ <Name>Physics</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Symbolism\Symbolism.csproj">
+ <Project>{067278C5-2A0F-42DE-838B-855EFB652608}</Project>
+ <Name>Symbolism</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Utils\Utils.csproj">
+ <Project>{A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}</Project>
+ <Name>Utils</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using Symbolism;
+using Physics;
+using Utils;
+
+namespace PSE_5E_Example_4._5_Thats_Quite_An_Arm
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ // A stone is thrown from the top of a building upward at an
+ // angle of 30.0° to the horizontal and with an initial speed of
+ // 20.0 m/s, as shown in Figure 4.12. If the height of the building
+ // is 45.0 m, (a) how long is it before the stone hits the ground?
+ // (b) What is the speed of the stone just before it strikes the
+ // ground?
+
+ 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(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, 0),
+ acceleration = _g,
+ };
+
+ var timeB = Calc.Time(objA, objB);
+
+ objB = objA.AtTime(timeB);
+
+ var timeC = timeB * 2;
+
+ var objC = objA.AtTime(timeC);
+
+ var yD = new Symbol("yD");
+
+ var objD = new Obj()
+ {
+ position = new Point(null, yD),
+ velocity = new Point(objA.velocity.x, null),
+ acceleration = _g
+ };
+
+ var timeAD = Calc.Time(objA, objD, 1);
+
+ objD = objA.AtTime(timeAD);
+
+ "How long is it before the stone hits the ground?".Disp();
+
+ "".Disp();
+
+ "Symbolic answer:".Disp();
+
+ timeAD.Disp();
+
+ "".Disp();
+
+ "Numeric answer:".Disp();
+
+ timeAD
+ .Substitute(g, 9.8)
+ .Substitute(thA, (30).ToRadians())
+ .Substitute(Trig.Pi, 3.14159)
+ .Substitute(vA, 20)
+ .Substitute(yD, -45)
+ .Disp();
+
+ "".Disp();
+
+ "What is the speed of the stone just before it strikes the ground?".Disp();
+
+ "".Disp();
+
+ "Symbolic answer:".Disp();
+
+ objD.velocity.Norm().Disp();
+
+ "".Disp();
+
+ "Numeric answer:".Disp();
+
+ objD.velocity.Norm()
+ .Substitute(g, 9.8)
+ .Substitute(thA, (30).ToRadians())
+ .Substitute(Trig.Pi, 3.14159)
+ .Substitute(vA, 20)
+ .Substitute(yD, -45)
+ .Disp();
+
+ Console.ReadKey();
+ }
+ }
+}
@@ -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 5E Example 4.5 Thats Quite An Arm")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("PSE 5E Example 4.5 Thats Quite An Arm")]
+[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("7d85439c-e51d-4870-bf05-665c89234f51")]
+
+// 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")]
View
@@ -7,6 +7,27 @@
namespace Physics
{
+ public static class Misc
+ {
+ public static MathObject QuadraticEquation(MathObject a, MathObject b, MathObject c, int solution=0)
+ {
+ if (a == new Integer(0) || a == new DoubleFloat(0.0))
+ throw new Exception("a is zero. Equation is not quadratic.");
+
+ var discriminant = b * b - 4 * a * c;
+
+ var half = new Integer(1) / 2;
+
+ if (solution == 0)
+ return (-b + (discriminant ^ half)) / (2 * a);
+
+ if (solution == 1)
+ return (-b - (discriminant ^ half)) / (2 * a);
+
+ throw new Exception();
+ }
+ }
+
public static class Trig
{
public static Symbol Pi = new Symbol("Pi");
@@ -62,6 +83,9 @@ public override string ToString()
public static Point operator /(Point a, MathObject b)
{ return new Point(a.x / b, a.y / b); }
+
+ public MathObject Norm()
+ { return (x * x + y * y) ^ (new Integer(1) / 2); }
}
public class Obj
@@ -98,10 +122,10 @@ public Obj AtTime(MathObject t)
};
}
}
-
+
public static class Calc
{
- public static MathObject Time(Obj a, Obj b)
+ public static MathObject Time(Obj a, Obj b, int solution = 0)
{
if (a.velocity.x != null &&
b.velocity.x != null &&
@@ -117,6 +141,27 @@ public static MathObject Time(Obj a, Obj b)
a.acceleration.y != new Integer(0))
return (b.velocity.y - a.velocity.y) / a.acceleration.y;
+ // yf = yi + vyi * t + 1/2 * ay * t^2
+ // 0 = 1/2 * ay * t^2 + vyi * t + yi - yf
+ // apply quadratic equation to find t
+
+ if (a.position.y != null &&
+ b.position.y != null &&
+ a.velocity.y != null &&
+ a.acceleration.y != null &&
+ a.acceleration.y != new Integer(0) &&
+ a.acceleration.y != new DoubleFloat(0.0))
+ {
+ var half = new Integer(1) / 2;
+
+ return
+ Misc.QuadraticEquation(
+ half * a.acceleration.y,
+ a.velocity.y,
+ a.position.y - b.position.y,
+ solution);
+ }
+
throw new Exception();
}
}
View
@@ -7,30 +7,82 @@ 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}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSE 5E Example 4.3 The Long-Jump", "PSE Example 4.3 The Long-Jump\PSE 5E Example 4.3 The Long-Jump.csproj", "{51C1B8ED-EDB7-443F-BE76-58A881EEFB20}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSE 5E Example 4.5 Thats Quite An Arm", "PSE 5E Example 4.5 Thats Quite An Arm\PSE 5E Example 4.5 Thats Quite An Arm.csproj", "{98A9D4E4-2AD1-4CC9-8697-C25097CA7420}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Utils.csproj", "{A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {067278C5-2A0F-42DE-838B-855EFB652608}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {067278C5-2A0F-42DE-838B-855EFB652608}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {067278C5-2A0F-42DE-838B-855EFB652608}.Debug|Mixed Platforms.Build.0 = Debug|x86
{067278C5-2A0F-42DE-838B-855EFB652608}.Debug|x86.ActiveCfg = Debug|x86
{067278C5-2A0F-42DE-838B-855EFB652608}.Debug|x86.Build.0 = Debug|x86
+ {067278C5-2A0F-42DE-838B-855EFB652608}.Release|Any CPU.ActiveCfg = Release|x86
+ {067278C5-2A0F-42DE-838B-855EFB652608}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {067278C5-2A0F-42DE-838B-855EFB652608}.Release|Mixed Platforms.Build.0 = Release|x86
{067278C5-2A0F-42DE-838B-855EFB652608}.Release|x86.ActiveCfg = Release|x86
{067278C5-2A0F-42DE-838B-855EFB652608}.Release|x86.Build.0 = Release|x86
+ {9E996759-C2E9-4265-A8CE-16341B26D1CC}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {9E996759-C2E9-4265-A8CE-16341B26D1CC}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {9E996759-C2E9-4265-A8CE-16341B26D1CC}.Debug|Mixed Platforms.Build.0 = Debug|x86
{9E996759-C2E9-4265-A8CE-16341B26D1CC}.Debug|x86.ActiveCfg = Debug|x86
{9E996759-C2E9-4265-A8CE-16341B26D1CC}.Debug|x86.Build.0 = Debug|x86
+ {9E996759-C2E9-4265-A8CE-16341B26D1CC}.Release|Any CPU.ActiveCfg = Release|x86
+ {9E996759-C2E9-4265-A8CE-16341B26D1CC}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {9E996759-C2E9-4265-A8CE-16341B26D1CC}.Release|Mixed Platforms.Build.0 = Release|x86
{9E996759-C2E9-4265-A8CE-16341B26D1CC}.Release|x86.ActiveCfg = Release|x86
{9E996759-C2E9-4265-A8CE-16341B26D1CC}.Release|x86.Build.0 = Release|x86
+ {73E0C26D-5333-4575-A3E9-5388E975446E}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {73E0C26D-5333-4575-A3E9-5388E975446E}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {73E0C26D-5333-4575-A3E9-5388E975446E}.Debug|Mixed Platforms.Build.0 = Debug|x86
{73E0C26D-5333-4575-A3E9-5388E975446E}.Debug|x86.ActiveCfg = Debug|x86
{73E0C26D-5333-4575-A3E9-5388E975446E}.Debug|x86.Build.0 = Debug|x86
+ {73E0C26D-5333-4575-A3E9-5388E975446E}.Release|Any CPU.ActiveCfg = Release|x86
+ {73E0C26D-5333-4575-A3E9-5388E975446E}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {73E0C26D-5333-4575-A3E9-5388E975446E}.Release|Mixed Platforms.Build.0 = Release|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|Any CPU.ActiveCfg = Debug|x86
+ {51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Debug|Mixed Platforms.Build.0 = Debug|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|Any CPU.ActiveCfg = Release|x86
+ {51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Release|Mixed Platforms.Build.0 = Release|x86
{51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Release|x86.ActiveCfg = Release|x86
{51C1B8ED-EDB7-443F-BE76-58A881EEFB20}.Release|x86.Build.0 = Release|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Debug|x86.ActiveCfg = Debug|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Debug|x86.Build.0 = Debug|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Release|Any CPU.ActiveCfg = Release|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Release|Mixed Platforms.Build.0 = Release|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Release|x86.ActiveCfg = Release|x86
+ {98A9D4E4-2AD1-4CC9-8697-C25097CA7420}.Release|x86.Build.0 = Release|x86
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {A3F0F5DB-7EB2-488F-B79C-F667C4E5AB02}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Oops, something went wrong.

0 comments on commit a9ce12f

Please sign in to comment.