Bonjour à tous et à toutes,
je dois créer une fonction creer qui va créer un type matrice. Mais j'ai des problèmes, surement au niveau des boucles.
Mon travail:
type info = {mutable c:float;i:int;j:int};;
(** le type info sert a stocker la valeur d’un coefficient et sa
position dans la matrice*)
type matrice ={ nb_lig:int; nb_col:int; mutable tab: info array};;
(*---------------------------------------------creer-------------------------------------*)
let creer n p =
let remplissage n p =
let mat = Array.create (n*p) ({c=0.0;i=1;j=1}) in
for l=0 to (n*p)-1 do
mat.(l)<-{c=0.0;i=1;j=l+1}
done;
for k=0 to (n*p)-1 do
mat.(k)<-{c=0.0;i=k+1;j=mat.(k).j}
done;
mat in
{nb_lig=n; nb_col=p; tab=remplissage n p};;
Mais j'ai un problème, par exemple
creer 2 3 retourne
[|{c = 0.; i = 1; j = 1}; {c = 0.; i = 2; j = 2}; {c = 0.; i = 3; j = 3};
{c = 0.; i = 4; j = 4}; {c = 0.; i = 5; j = 5}; {c = 0.; i = 6; j = 6}|]}
Et le résultat attendu serait plutôt:
[|{c = 0.; i = 1; j = 1}; {c = 0.; i = 1; j = 2}; {c = 0.; i = 1; j = 3};
{c = 0.; i = 2; j = 1}; {c = 0.; i = 2; j = 2}; {c = 0.; i = 2; j = 3}|]}.
Merci.
PS: Un algorithme me suffira vu que je n'ai aucun problème avec le langage lui même.
Jeremux.
Partager