Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let sous_list a b=
- List.map (fun (a,b) -> a -. b) (List.combine a b )
- ;;
- let mult_list a b=
- List.map (fun (a,b) -> a *. b) (List.combine a b )
- ;;
- let add_list l = List.fold_left (+.) 0. l
- ;;
- let add a l = List.rev (a::(List.rev l));;
- let rec solve = function
- | [[a;k]] -> [-. k/. a]
- | pivot::mat ->
- match pivot with
- | a::line ->
- (* On détermine le coefficient multiplicatif pour chaque équation *)
- let k = List.map (fun b -> a /. (List.hd b)) mat in
- let kl = List.combine k mat in
- (* Et on le multiplie a chaque élement de chaque équation *)
- let nmat = List.map (fun (k, l) -> List.map (( *. ) k) l) kl in
- (* On soustrait chaque équation par le pivot *)
- (* On se retrouve donc avec un système à n-1 inconnues*)
- let nnmat = List.map (fun l -> sous_list (List.tl l) line) nmat in
- let sols = solve nnmat in
- let l = add 1. sols in
- let r = -. add_list (mult_list l line) in
- r::sols
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement