You are on page 1of 4

Ex 1 

1) > max3:=proc(a::posint,b::posint,c::posint)

local max2;
max2:=proc(x::posint,y::posint)
if x>y then x else y end if;
end proc;
max2(a,max2(b,c));
end proc;
> max(7,8,9);

2) restart;

second_degre := proc(a, b, c)
local ;
if a0 then print( "a doit etre non nul")
else
 := b^24ac;

if 0 then print( "pas de solution")


elif 0 then print( "racine double : ", x1/2b/a )
else print( "2 racines distinctes:", x1/2( bsqrt (  ) )/a,
x1/2( bsqrt (  ) )/a )
end if

end if
end proc
> second_degre(1,-5,+6);
"2 racines distinctes:", x2, x3
> second_degre(1,-2,9);
"pas de solution"
> second_degre(0,0,0);
"a doit etre non nul"
> second_degre(1,0,-1);
"2 racines distinctes:", x-1, x1
> second_degre(1,0,1);
"pas de solution"

3)
> somme:=proc(n::nonnegint)
if n=0 then 0 else n + somme(n-1) end if;
end proc;
somme := proc(n::nonnegint) if n0 then 0 else nsomme( n1 ) end if end proc
> somme(20);

4) > renverser:=proc(n::posint)
local a,i,L,n1,n2;
n2:=0;n1:=n;
L:=floor(ln(n)/ln(10))+1; # longueur du nombre
for i from L-1 to 0 by -1 do
a:=floor(n1/(10^i));
if a=0 then error "le chiffre 0 n'est pas autorisé" else
n2:=n2+10^(L-1-i)*a; n1:=n1-a*10^i;
end if;
end do;
n2
end proc;

> renverser(1618);
8161
> renverser(12001);
Error, (in renverser) le chiffre 0 n'est pas autorisé
5)
> VDM:=proc(n::posint)
local i,j,a,V;
a:=array(1..n); V:=array(1..n,1..n);
for i to n do for j to n do
V[i,j]:=a[i]^(j-1)
end do;
end do;
print(V);
end proc;
Ex3 :
> T:=array([[4,1,2],[3,5,6],[7,9,2]]);
 4 1 2
 
T :=  3 5 6
 
 7 9 2
> ligne:=proc(T::array,p::posint,i::posint)
local j,s;
s:=0;
for j from 1 to p by 1 do
s:=s + T[i,j];
od; # od ou end do;
s;
end proc;
ligne := proc(T::array, p::posint, i::posint)
local j, s;
s := 0 ; for j to p do s := sT[ i, j ] end do; s
end proc
> colonne:=proc(T::array,n::posint,j::posint)
local i,s;
s:=0;
for i to n do
s:=s + T[i,j];
od; # od ou end do;
s;end proc;
colonne := proc(T::array, n::posint, j::posint)
local i, s;
s := 0 ; for i to n do s := sT[ i, j ] end do; s
end proc
> colonne(T,3,1);
14
> colonne(T,3,2);
15
> colonne(T,3,3);
10
> diagonale:=proc(T::array,n::posint)
local i,s;
s:=0;
for i to n do
s:=s + T[i,i];
od; # od ou end do;
s;end proc;
diagonale := proc(T::array, n::posint)
local i, s;
s := 0 ; for i to n do s := sT[ i, i ] end do; s
end proc
> diagonale(T,1);
>
4
> T:=matrix([[4,1,2],[3,5,6],[7,9,2]]);
 4 1 2
 
T :=  3 5 6
 
 7 9 2
> N:=matrix([[4,1,2],[3,5,6],[7,9,2]]);
 4 1 2
 
N :=  3 5 6
 
 7 9 2
> egal:=proc(T::matrix,N::matrix)
local p,q;
if rowdim(T)=rowdim(N) and coldim(T)=coldim(N) then
for p to rowdim(T) do
for q to coldim(N) do
if T[p,q]<>N[p,q] then return(false)
end if;
od;
od;
return(true)
else return(false)
end if;
end proc;

> with(linalg); #OBLIGE SINON CA MARCHERA PAS !!

> egal(T,N);
true
> N:=array([[2,1,3],[4,8,9],[6,6,6]]);
 2 1 3
 
N :=  4 8 9
 
 6 6 6
> egal(T,N);
false

You might also like