Compile a Module
- To: mathgroup at smc.vnet.net
- Subject: [mg83148] Compile a Module
- From: JOHN ERB <john_c_erb at prodigy.net>
- Date: Tue, 13 Nov 2007 03:35:52 -0500 (EST)
Can the following module be compiled? It needs to be used 10^4 times in my program. It is used to calculate the distance parallel and perpendicular to the midpoint of 2D line segment with reference to a point of interest (calc). AlongAway[{tip_,end_,calc_}]:=Module[{mid,r,theta,along,away}, mid=(tip+end)/2; r=Sqrt[Dot[calc-mid,calc-mid]]; theta=VectorAngle[calc-mid,end-mid]; along=r Cos[theta]; away=r Sin[theta]; {along,away}] AlongAway[{{-1, 0}, {1, 0}, {2, 1}}] (* answer is {2,1} *) (* the code below does not seem to work *) cAlongAway=Compile[{{tip,_Real},{end,_Real},{calc,_Real}},AlongAway] John C. Erb