Skip to content

Commit 6e2230e

Browse files
author
Oskar Lundström
committed
Merge branch 'oskar'. Commitade rapporten på fel branch av misstag
2 parents b445434 + e162e9f commit 6e2230e

File tree

7 files changed

+428
-322
lines changed

7 files changed

+428
-322
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
2+
{-# LANGUAGE TypeOperators #-}
3+
{-# LANGUAGE MultiParamTypeClasses #-}
4+
{-# LANGUAGE FlexibleInstances #-}
5+
6+
module Combination.Calculus where
7+
8+
import Calculus.FunExpr
9+
import Calculus.DifferentialCalc
10+
import Calculus.IntegralCalc
11+
12+
import Combination.Quantity
13+
import Dimensions.TypeLevel
14+
15+
import Combination.Vector
16+
17+
import Prelude hiding (length)
18+
19+
-- FunExpr är redan Num-instans, så borde inte behöva göra detta,
20+
-- men pga okända anledningar funkar det ej
21+
22+
instance Addable FunExpr FunExpr FunExpr where
23+
doAdd = (+)
24+
25+
instance Subable FunExpr FunExpr FunExpr where
26+
doSub = (-)
27+
28+
instance Multiplicable FunExpr FunExpr FunExpr where
29+
doMul = (*)
30+
31+
instance Divisionable FunExpr FunExpr FunExpr where
32+
doDiv = (:/)
33+
34+
-- Det intressanta är att den är Calculable! Num är faktiskt inte det
35+
-- så här blir det spännande.
36+
37+
instance Calculable FunExpr where
38+
doDif = simplify . derive
39+
doInteg = simplify . integrate
40+
41+
42+
----------------------------------------
43+
-- Exempel
44+
----------------------------------------
45+
46+
-- Ett flygplan med viss position är nedanstående
47+
48+
g1 = V3 Id (Const 3 :* Exp) Sin ## length
49+
50+
-- Dess hastighet är
51+
52+
g2 :: Quantity (Length `Div` Time) (Vector3 FunExpr)
53+
g2 = diff g1
54+
55+
-- Dess acceleration är
56+
57+
g3 :: Quantity ((Length `Div` Time) `Div` Time) (Vector3 FunExpr)
58+
g3 = diff g2
59+
60+
-- Det väger 120 kg
61+
62+
g4 :: Quantity Mass FunExpr
63+
g4 = Const 120 ## mass
64+
65+
-- Så nettokraften är
66+
67+
g5 :: Quantity (Mass `Mul` ((Length `Div` Time) `Div` Time)) (Vector3 FunExpr)
68+
g5 = g4 *# g3
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+

Physics/src/Combination/Combination.hs

Lines changed: 0 additions & 227 deletions
This file was deleted.

0 commit comments

Comments
 (0)