Accueil > Mathématiques > Maths & logiciels > Fragments maxima

Fragments maxima

mercredi 16 novembre 2011, par Vincent

Forme canonique d’un polynôme du second degré

formecanonique(exp):=block([s,a,c],

/* initialisation */

s:rhs(solve(diff(exp,x),x)[1]),
a:diff(exp,x,2)/2,
c:fullratsimp(subst(s,x,exp)),

return(a*(x-s)^2+c))$

usage :

(%i10) formecanonique(x^2-6*x+4);
                                         2                                    
(%o10)                           (x - 3)  - 5

Identité de Bézout

mymod(a,b) := divide(a,b)[2]$
 
 
 bezoutinteger(a,b) := block([c,d,e,f,g,h,i,j,r,q,t,s,o,A,B],
 /* initialisation */
   s:0,
   A:a,
   B:b,
   d:1,
   e:0,
   g:0,
   h:1,
 
 /* on prend le + grand dans la variable a */
   if a < b then (
     c:a,
     a:b,
     b:c,
     s:1),
 
 /* début du process */
   t:divide(a,b),
   r:t[2],
   q:t[1],
   print("",a,"=",q,"\\times",b,"+",r),
   while r > 0 do (
 /*    On continue tant que r > 0     */
     f:d-q*e,
     i:g-q*h,
     d:e,
     e:f,
     g:h,
     h:i,
     a:b,
     b:r,
     t:divide(a,b),         
     r:t[2],     
     q:t[1],
     print("",a,"=",q,"\\times",b,"+",r)),
 
 /* conclusion */
   if s = 1 then (
     print("",i,"\\times",A,"+",f,"\\times",B,"=",b),
     o:[i,f,b])
   else (
     print("",f,"\\times",A,"+",i,"\\times",B,"=",b),
     o:[f,i,b]),
   return(o))$

usage :

(%i7) load("bezout.mac");

(%i8) bezoutinteger(13,1245);
 1245 = 95 \times 13 + 10 
 13 = 1 \times 10 + 3 
 10 = 3 \times 3 + 1 
 3 = 3 \times 1 + 0 
 - 383 \times 13 + 4 \times 1245 = 1 
(%o8)                            [- 383, 4, 1]

Voir en ligne : Le site officiel de Maxima