# Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 2.61 KB  |  hits: 12  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. Derivatives of a multivariative function and corresponding Jacobian with vector-space package
2. f:(0,oo) x [0,2pi] -> R²
3. (r,phi) -> (r*cos(phi),r*sin(phi))
4.
5. polar :: Double -> Double -> ((Double,Double) :~> (Double,Double))
6. polar r phi = (r,phi) ->  (((idD) r)*cos( idD phi),((idD) r)*sin( idD phi))
7.
8. Couldn't match expected type `(Double, Double) :> (Double, Double)'
9.             with actual type `(t0, t1)'
10. In the expression:
11.   (((idD) r) * cos (idD phi), ((idD) r) * sin (idD phi))
12. In the expression:
13.    (r, phi)
14.     -> (((idD) r) * cos (idD phi), ((idD) r) * sin (idD phi))
15. In an equation for `polar':
16.     polar r phi
17.       =  (r, phi)
18.           -> (((idD) r) * cos (idD phi), ((idD) r) * sin (idD phi))
19.
20. polarx :: Double -> Double -> ((Double,Double) :~> Double)
21. polarx r phi = (r,phi) ->  ((idD) r)*cos( idD phi)
22.
23. Couldn't match expected type `Double'
24.             with actual type `(Double, Double)'
25. Expected type: (Double, Double) :> Double
26.   Actual type: (Double, Double) :> (Double, Double)
27. In the return type of a call of `idD'
28. In the first argument of `(*)', namely `((idD) r)'
29.
30. polarCoordD :: ((Double,Double) :~> (Double,Double))
31. polarCoordD = (r,phi) ->  pairD (polarx (r,phi), polary (r,phi))
32. where polarx :: (Double,Double) :~> Double
33.       polarx = (r,phi) -> (fst . unpairD \$ (idD) (r,phi))*cos( snd . unpairD \$ idD (r, phi))
34.       polary :: (Double,Double) :~> Double
35.       polary = (r,phi) -> (fst . unpairD \$ (idD) (r,phi))*sin( snd . unpairD \$ idD (r, phi))
36.
37. cylCoordD :: (Vec3 Double :~> Vec3 Double)
38. cylCoordD = (r,phi,z) ->  tripleD (cylx (r,phi,z), cyly (r,phi,z),cylz (0,0,z))
39. where cylx :: (Double,Double,Double) :~> Double
40.       cylx = (r,phi,z) -> (fst' . untripleD \$ (idD) (r,phi,z))*cos( snd' . untripleD \$ idD (r, phi,z))
41.       cyly :: (Double,Double,Double) :~> Double
42.       cyly = (r,phi,z) -> (fst' . untripleD \$ (idD) (r,phi,z))*sin( snd' . untripleD \$ idD (r, phi,z))
43.       cylz :: (Double,Double,Double) :~> Double
44.       cylz = (_,_,z) -> third . untripleD \$ idD (0,0,z)
45.       fst' :: (a,b,c) -> a
46.       fst' (x,_,_) = x
47.       snd' :: (a,b,c) -> b
48.       snd' (_,y,_) = y
49.       third :: (a,b,c) -> c
50.       third (_,_,z) = z
51.
52. let transmat = (r,phi,z) -> powVal \$ liftD3 (,,) (normalized \$ derivAtBasis (cylCoordD (r,phi,z)) (Left ())) (normalized \$ derivAtBasis (cylCoordD (r,phi,z)) (Right (Left ()))) (normalized \$ derivAtBasis (cylCoordD (r,phi,z)) (Right (Right ())))
53.
54. *Main> transmat (2, rad 0, 0)
55. ((1.0,0.0,0.0),(0.0,1.0,0.0),(0.0,0.0,1.0))
56.
57. *Main> transmat (2, rad 90, 0)
58. ((6.123233995736766e-17,1.0,0.0),(-1.0,6.123233995736766e-17,0.0),(0.0,0.0,1.0))
59.
60. rad :: Double -> Double
61. rad = (pi*) . (*recip 180)