Je produis tous mes dessins (cours, DS...) avec latex+Asymptote depuis quelque temps. J'ai beaucoup profité des contributions de Philippe Ivaldi et de Gaétan.
Je les en remercie chaleureusement.
Voici une modeste contribution. C'est une extension qui permet d'effectuer et de dessiner une division euclidienne de polynômes.
Ca traine depuis deux ans sur mon disque dur, si ça peut être utile à quelqu'un j'en serais content.
Je ne l'ai moi même qu'assez peu utilisée, elle est peut-être buggée: vérifier avec xcas ne coûte pas cher.
Edition par GM le 22/03 : une version modifiée du code suivant est proposée dans une réponse qui suit.
voici le fichier diveucl_dev.asy à mettre au bon endroit (sous linux dans ~/.asy/)
Code : Tout sélectionner
void diveucli(picture pic=currentpicture,
real[] dividende,
real[] diviseur,
real xunite=12mm,
real yunite=8mm)
{
unitsize(pic,xunite,yunite);
real[] divid,divis,sous;
divid=dividende;
divis=diviseur;
int l1=divid.length, l2=divis.length;
real a,b,p,q,s;
pair Q,S,D;
string ch;
for(int i=0; i < l1; ++i){
a=l1-i-1;
b=dividende[i];
if(b==0){ch="";} else{
if(a==0){
if(0<b){ch="$+" + (string) b + "$";}
else {ch="$" + (string) b + "$";}
}
else{
if(a==1){
if(0<b){ch="$+" + (string) b+"x$";}
else {ch="$" + (string) b+"x$";}
}
else{
if(0<b){ch="$+" + (string) b+"x^{" + (string) a + "}$";}
else {ch="$" + (string) b+"x^{" + (string) a + "}$";}
}
}
}
draw(pic,ch,(i,0));
}
draw(pic,(l1,.5)--(l1,-3));
draw(pic,(l1,-.5)--(l1+l2+1,-.5));
for(int i=0; i < l2; ++i){
a=l2-i-1;
b=diviseur[i];
if(b==0){ch="";} else{
if(a==0){
if(0<b){ch="$+" + (string) b + "$";}
else {ch="$" + (string) b + "$";}
}
else{
if(a==1){
if(0<b){ch="$+" + (string) b+"x$";}
else {ch="$" + (string) b+"x$";}
}
else{
if(0<b){ch="$+" + (string) b+"x^{" + (string) a + "}$";}
else {ch="$" + (string) b+"x^{" + (string) a + "}$";}
}
}
}
draw(pic, ch,(i+l1+1,0));
}
// on initialise les positions des polynomes
Q=(l1+1,-1);
S=(0,-1);
D=(0,-2);
while(divis.length<=divid.length){
//for(int i=0; i < 1; ++i){
p=divid.length-divis.length;
q=divid[0]/divis[0];
// on ecrit un bout de quotient
a=p;
b=q;
if(b==0){ch="";} else{
if(a==0){
if(0<b){ch="$+" + (string) b + "$";}
else {ch="$" + (string) b + "$";}
}
else{
if(a==1){
if(0<b){ch="$+" + (string) b+"x$";}
else {ch="$" + (string) b+"x$";}
}
else{
if(0<b){ch="$+" + (string) b+"x^{" + (string) a + "}$";}
else {ch="$" + (string) b+"x^{" + (string) a + "}$";}
}
}
}
draw(pic, ch,Q);
sous=q*divis;
s=sous.length;
// on ecrit ce qu'on soustrait au dividende
for(int j=0; j < s; ++j){
a=s-j-1+p;
b=sous[j];
if(b==0){ch="";} else{
if(a==0){
if(0<b){ch="$+" + (string) b + "$";}
else {ch="$" + (string) b + "$";}
}
else{
if(a==1){
if(0<b){ch="$+" + (string) b+"x$";}
else {ch="$" + (string) b+"x$";}
}
else{
if(0<b){ch="$+" + (string) b+"x^{" + (string) a + "}$";}
else {ch="$" + (string) b+"x^{" + (string) a + "}$";}
}
}
}
draw(pic, ch,S+(j,0));
}
// on cree le nouveau dividende
l1=divid.length;
for(int j=0; j < l1-s; ++j){ sous.push(0);}
draw(pic,S+(-0.5,-0.5)--S+(s-0.5,-0.5));
divid=divid-sous;
l1=divid.length;
// on ecrit le nouveau dividende
for(int j=0; j < l1; ++j){
a=l1-j-1;
b=divid[j];
if(b==0){ch="";} else{
if(a==0){
if(0<b){ch="$+" + (string) b + "$";}
else {ch="$" + (string) b + "$";}
}
else{
if(a==1){
if(0<b){ch="$+" + (string) b+"x$";}
else {ch="$" + (string) b+"x$";}
}
else{
if(0<b){ch="$+" + (string) b+"x^{" + (string) a + "}$";}
else {ch="$" + (string) b+"x^{" + (string) a + "}$";}
}
}
}
draw(pic, ch,D+(j,0));
}
// on vire les zeros du debut du dividende
a=0;
while(divid[0]==0){
divid.delete(0);
a=a+1;
}
Q=Q+(1,0);
S=S+(a,-2);
D=D+(a,-2);
}
}
Code : Tout sélectionner
import diveucl_dev;
picture dessin;
real[] dividende={1,3,3,7,-34,16},diviseur={1,3,-2};
diveucli(dessin,dividende,diviseur,12mm,8mm);
shipout(dessin);