bool Function(objet)
{
pour chaque élément de l'objet
si element == "élémentaire"
alors Traitement(...)
return TRUE
sinon
Fonction(element)
return FALSE
fin si
fin pour
return TRUE
}
Dlzlogic a écrit:[/CODE]Je n'imagine pas comment une fonction récursive pourrait être en "mode terminal"
On dit quun fonction est récursive terminale, si tout appel récursif
est de la forme return f(...)
( 1)bifur := proc (rmin, rmax, n, u0, e, p, m)
( 2) local un, etapun, f, k, L, r;
( 3) L := [];
( 4)
( 5) un := proc (r, n)
( 6) local u, i, f;
( 7) f :=x-> x*r*(1-x);
( 8) u := u0;
( 9) for i to n
(10) do
(11) u := f(u)
(13) end do;
(14) u ;
(15) end proc;
(16)
(17) for r from rmin by p to rmax
(18) do
(19) k := 2;
(20) if abs(un(r, n)-un(r, n+1)) < e
(21) then
(22) L := [op(L), [r, un(r, n)]]
(23) else
(24) L := [op(L), [r, un(r, n)], [r, un(r, n+1)]];
(25)
(26) while e < abs(un(r, n)-un(r, n+k)) and k < m
(27) do
(28) k := k+1;
(29) L := [op(L), [r, un(r, n+k)]]
(30) end do
(31) end if
(32) end do;
(33) plots:-pointplot(L, style = point, symbol = point, trickness = 0)
(34)end procArchytas a écrit:D'accord le voici :
[CODE]bifur := proc (rmin, rmax, n, u0, e, p, m)
local un, etapun, f, k, L, r;
L := [];
un := proc (r, n)
local u, i, f;
f :=x-> x*r*(1-x);
u := u0;
for i to n do u := f(u) end do;
u ;
end proc;
for r from rmin by p to rmax do
k := 2;
if abs(un(r, n)-un(r, n+1)) et je préfère "unapply". A mon avis,f :=x-> x*r*(1-x);
serait avantageusement changé enf := unapply(x*r*(1-x), x);
Par ailleurs, tu utilises une liste L pour collecter des objets. Or c'est nettement plus joli de le faire avec une suite : cela évite des opérations op() pour libérer les [], puis remettre des crochets [] pour revenir à une liste, en permanence !(...)
L := [];
(...)
if abs(un(r, n)-un(r, n+1)) < e then L := [op(L), [r, un(r, n)]]
else
L := [op(L), [r, un(r, n)], [r, un(r, n+1)]];
(...)
L := [op(L), [r, un(r, n+k)]] end do
plots:-pointplot(L, style = point, symbol = point, trickness = 0)
end proc
serait amélioré en(...)
L := NULL; # L = suite vide
(...)
if abs(un(r, n)-un(r, n+1)) < e then L := L, [r, un(r, n)]
else
L := L, [r, un(r, n)], [r, un(r, n+1)];
(...)
L := L, [r, un(r, n+k)] end do
plots:-pointplot( [ L ] , style = point, symbol = point, trickness = 0)
end proc
k := 2;
if abs(un(r, n)-un(r, n+1)) < e then L := [op(L), [r, un(r, n)]]
else
L := [op(L), [r, un(r, n)], [r, un(r, n+1)]];
while e < abs(un(r, n)-un(r, n+k)) and k < m do
k := k+1;
L := [op(L), [r, un(r, n+k)]] end do
end if
L := L, [r, un(r, n)] ;
for k to ceil(m)-1 while e < abs(un(r, n)-un(r, n+k)) do
L := L, [r, un(r, n+k)]
end do
k := 2;
if abs(un(r, n)-un(r, n+1)) < e then L := [op(L), [r, un(r, n)]]
else
L := [op(L), [r, un(r, n)], [r, un(r, n+1)]];
while e < abs(un(r, n)-un(r, n+k)) and k < m do
k := k+1;
L := [op(L), [r, un(r, n+k)]] end do
end if
L := L, [r, un(r, n)] ;
for k to ceil(m)-1 while e < abs(un(r, n)-un(r, n+k)) do
L := L, [r, un(r, n+k)]
end do
bifur := proc (rmin, rmax, n, u0, e, p, m)
local un, etapun, f, k, L, r;
L := NULL ;
un := proc (r, n)
local u, i, f;
f := unapply(x*r*(1-x), x);
return (f@@n)(u0) ;
end proc;
for r from rmin by p to rmax do
L := L, [r, un(r, n)] ;
for k to ceil(m)-1 while e < abs(un(r, n)-un(r, n+k)) do
L := L, [r, un(r, n+k)]
end do
end do
plots:-pointplot([L], style = point, symbol = point, trickness = 0)
end proc
Archytas a écrit:Ce qui me gène que ce soit liste ou séquence c'est de garder les valeur calculer et les afficher à la fin, c'est extrèmement long !!!! Point par point ça se ferais en quelques minutes tout au plus.
Archytas a écrit:Si je peux me permettre une petite explication de mon code pour qu'éventuellement vous me disiez s'il y a des erreurs de logique ou des maladresse chronophages :id: !
un(r,n) calcul la n ème valeur de la suite (f@@n)(u0). Ensuite je compare deux termes consécutifs pour n "grand" s'ils sont très proches (la valeur absolue de leur différence est inférieur à "e" petit) j'en conclu qu'il sera de même pour ceux qui suivent.
leon1789 a écrit:On peut optimiser le code en ce qui concerne le calcul des un(r,n) , un(r,n+1), un(r,n+2), ... sans repartir de u0 à chaque fois. A suivre.
for r from rmin by p to rmax do
L := L, [r, un(r, n)] ;
for k to ceil(m)-1 while e abs(v-u) then break end if ; # on sort de la boucle for k
L := L, [r, u]
end do
end do
bifur := proc (rmin, rmax, n, u0, e, p, m)
local u,v, f, k, L, r;
L := NULL ;
for r from rmin by p to rmax do
f := unapply(x*r*(1-x), x);
v := (f@@n)(u0) ; # ici, v = un(r, n)
L := L, [r, v] ;
u := v ;
for k to ceil(m)-1 do
u := f(u) ; # ici, u = un(r, n+k)
if e > abs(v-u) then break end if ; # on sort de la boucle for k
L := L, [r, u]
end do
end do ;
plots:-pointplot([L], style = point, symbol = point, trickness = 0)
end proc ;
adrien69 a écrit:Un algorithme sans commentaire c'est comme un pet. C'est bien seulement si c'est le tien.
L := [r, v], L ;
(...)
L := [r, u], L ;
L := L, [r, v] ;
(...)
L := L, [r, u] ; adrien69 a écrit:Un algorithme sans commentaire c'est comme un pet. C'est bien seulement si c'est le tien.
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 36 invités
Tu pars déja ?
Identification
Pas encore inscrit ?
Ou identifiez-vous :