Geometry Module in Erlang

Planning to build some geometry module to do various calculations. 

here goes some line functions

 

-module(lineFunc).
-compile(export_all). 
% This function takes line of form Ax + By + C = 0; 
lineFunc(Ax,By,C) ->
  {fun(Y) ->   - (By * Y + C)/Ax end, fun(X) -> -(Ax * X + C )/By end}.

% Gives two functions to find value at various points ,Xintercept, Yintercept and Slope
make_line(A,B,C) ->
  Xintercept = case A of 0 -> infinity; A-> -C / A end, 
  Yintercept = case B of 0 -> infinity; B -> -C / B end, 
  Slope = (Yintercept - 0 )/ (0 - Xintercept),  
  {XatY, YatX } = lineFunc(A,B,C),
  [XatY,YatX,Xintercept,Yintercept,Slope].

%%line_inequality(A,B,C,Symbol) ->
%%  fun(X,Y) -> 

line_intersection([_,_,X,Y,S1], [_,_,Xd,Yd, S2]) ->
  case S1 of 
    S2 -> {parallel_lines};
    S1 ->
      Deno =  (Y*Xd - X * Yd),
      {( X*Y*Xd - X * Xd * Yd)/ Deno, ( - X* Y * Yd+ Y * Xd * Yd)/ Deno}
  end
Advertisements

Genetic Algorithm Erlang

Ok So another project that I will be working on.. .
GA for portfolio optimisation.. 
Day1. 
-module(genPort).
-compile(export_all). 

randList(N) ->
  UnNormalized = [random:uniform() || _ <- lists:seq(1,N)], 
  S = lists:sum(UnNormalized),
  lists:map(fun(X) -> X/S end, UnNormalized). 

randPopulations (N,P) ->
  randPopulationsH(N,P,[]). 
%% Can be changed later right now very simple
fitness(PRisk,PRet) ->
    PRet/PRisk. 

fitnessFunctionH(Population,Risk,Return,FitList)->
  case Population of 
    [] -> FitList; 
    [Specimen|T] -> 
  PortFolioRiskReturnList = lists:zipwith3( fun(P,Ri,Ret) -> {P*Ri,P*Ret} end, Specimen,Risk, Return),
%SpecimentFitness = lists:foldl(fun({X,Y},A) -> fitness(X,Y) + A end, 0, PortFolioRiskReturnList), 
%fitnessFunctionH(T,Risk,Return,FitList ++ [SpecimentFitness])
fitnessFunctionH(T,Risk,Return,FitList ++ [PortFolioRiskReturnList] )
end.
%%%%%%%%%%%%%%        HELPER FUNCTIONS GOES HERE %%%
randPopulationsH(N,Population,List) ->
  case Population of 
    0 -> List; 
    P -> randPopulationsH(N,P-1,List ++ [randList(N)])
  end