suivant: Index monter: CN_ECS précédent: Exercices   Table des matières   Index

QCM corrigés

Exercice 23   On pose v=[1:5]'. Quelles affirmations sont correctes ?
  1. \fbox{\phantom{\bf x}} v*v'==v'*v donne $ 1$
  2. \fbox{\phantom{\bf x}} v*v'==v'*v donne T
  3. \fbox{{\bf x}} v*v' est une matrice
  4. \fbox{\phantom{\bf x}} v*v est une matrice
  5. \fbox{{\bf x}} v'*v-norm(v).^2 donne 0

Exercice 24   On pose A=[ 1:3 ; 2,2,2 ; 3:-1:1] et v=[3:-1:1]', quelles affirmations sont correctes ?
  1. \fbox{{\bf x}} v'*v vaut 14
  2. \fbox{\phantom{\bf x}} v.*v vaut 14
  3. \fbox{{\bf x}} v'*A*v est un réel
  4. \fbox{\phantom{\bf x}} v==v(3:-1:1) donne $ T$
  5. \fbox{{\bf x}} v==v(3:-1:1) donne [ F T F ]'
  6. \fbox{{\bf x}} v(3:-1:1)==A(:,1) donne [T T T]';
  7. \fbox{\phantom{\bf x}} v(3:-1:1)==A(1,:) donne [T T T];

Exercice 25   Parmi les lignes de commande suivantes, lesquelles affichent le vecteur ligne
v=[1,2,3,4,5] ?
  1. \fbox{\phantom{\bf x}} v=[1;2;3;4;5]
  2. \fbox{\phantom{\bf x}} v=[1,2,3,4,5];
  3. \fbox{\phantom{\bf x}} [1:5]; v
  4. \fbox{{\bf x}} v=[1:5]
  5. \fbox{\phantom{\bf x}} v=[1:5];
  6. \fbox{{\bf x}} [1:5]; v=ans
  7. \fbox{\phantom{\bf x}} v=[1;5]
  8. \fbox{\phantom{\bf x}} v=[1:10]; v(1,5)
  9. \fbox{{\bf x}} v=[1:10]; v(1,[1:5])
  10. \fbox{\phantom{\bf x}} v=linspace(1,5)
  11. \fbox{{\bf x}} v=linspace(1,5,5)
  12. \fbox{{\bf x}} v=cumsum(ones(1,5))
  13. \fbox{\phantom{\bf x}} v=cumsum(ones(5,1))
  14. \fbox{{\bf x}} v=find(ones(5,1)==1)
  15. \fbox{\phantom{\bf x}} v=find(rand(1,5)<0)
  16. \fbox{{\bf x}} v=find(rand(1,5)<1)
  17. \fbox{{\bf x}} v=find(zeros(1,5)<=0)
  18. \fbox{\phantom{\bf x}} v=sort([1,3,2,5,4])
  19. \fbox{\phantom{\bf x}} v=sort([1;3;2;5;4]); v([5:-1:1])
  20. \fbox{{\bf x}} v=sort([1,3,2,5,4]); v([5:-1:1])
  21. \fbox{\phantom{\bf x}} v=gsort([1,3,2,5,4],"r","i")
  22. \fbox{{\bf x}} v=gsort([1,3,2,5,4],"c","i")
  23. \fbox{{\bf x}} v=gsort([1;3;2;5;4],"r","i"); v=v'
  24. \fbox{\phantom{\bf x}} for i=1:5, v=i; end
  25. \fbox{\phantom{\bf x}} for i=1:5, v=[v,i]; end; v
  26. \fbox{{\bf x}} v=[]; for i=1:5, v=[v,i]; end; v
  27. \fbox{\phantom{\bf x}} v=1; for i=1:5, v=[v,v($)+1]; end; v
  28. \fbox{{\bf x}} v=1; for i=1:4, v=[v,v($)+1]; end; v
  29. \fbox{\phantom{\bf x}} i=0; v=i; while i<=5, i=i+1; v=[v,i]; end; v
  30. \fbox{\phantom{\bf x}} i=1; v=i; while i<=5, i=i+1; v=[v,i]; end; v
  31. \fbox{{\bf x}} i=1; v=i; while i<5, i=i+1; v=[v,i]; end; v

Exercice 26   Parmi les lignes de commande suivantes, lesquelles affichent le vecteur ligne
v=[1,0.5,0.25,0.125,0.0625] ?
  1. \fbox{{\bf x}} 2^(-[0:4])
  2. \fbox{\phantom{\bf x}} 2^-[0:4]
  3. \fbox{\phantom{\bf x}} 1/2^[0:4]
  4. \fbox{\phantom{\bf x}} (1)/2^[0:4]
  5. \fbox{{\bf x}} (1)./2^[0:4]
  6. \fbox{\phantom{\bf x}} v=cumprod(ones(1,5)/2)
  7. \fbox{{\bf x}} v=[1,cumprod(ones(1,4)/2)]
  8. \fbox{{\bf x}} v=cumprod([1,0.5*ones(1,4)])
  9. \fbox{\phantom{\bf x}} for i=0:4, v=2^(-i); end;
  10. \fbox{{\bf x}} v=[]; for i=0:4, v=[v,2^(-i)]; end; v
  11. \fbox{\phantom{\bf x}} v=[1]; for i=1:4, v=[v,v/2]; end; v
  12. \fbox{{\bf x}} x=1; v=[x]; for i=1:4, x=x/2; v=[v,x]; end; v
  13. \fbox{\phantom{\bf x}} x=1; v=[x]; for i=1:4, v=[v,x/2]; end; v
  14. \fbox{\phantom{\bf x}} x=1; v=[x]; while x>0.06, x=x/2; v=[v,x]; end; v
  15. \fbox{{\bf x}} x=1; v=[x]; while x>0.1, x=x/2; v=[v,x]; end; v

Exercice 27   Parmi les lignes de commande suivantes, lesquelles affichent la matrice carrée à deux lignes et deux colonnes A, dont la première ligne est le vecteur [0,1] et la deuxième ligne est le vecteur [1,0] ?
  1. \fbox{{\bf x}} A=[0,1;1,0]
  2. \fbox{\phantom{\bf x}} A=[0,1]; A=[A,[1,0]]
  3. \fbox{{\bf x}} A=[0,1]; A=[A;[1,0]]
  4. \fbox{\phantom{\bf x}} A=[0;1]; A=[A;[1;0]]
  5. \fbox{{\bf x}} A=[0;1]; A=[A,[1;0]]
  6. \fbox{\phantom{\bf x}} A=[0,1]; A=A+A'
  7. \fbox{\phantom{\bf x}} A=[0,1]; A=[A;A]
  8. \fbox{{\bf x}} A=[0,1]; A=[A;A([2,1])]
  9. \fbox{\phantom{\bf x}} A=[0,1]; A=[A;A(2,1)]
  10. \fbox{{\bf x}} A(1,2)=1; A(2,1)=1
  11. \fbox{{\bf x}} A=ones(2,2); A(1,1)=0; A(2,2)=0
  12. \fbox{\phantom{\bf x}} A=eye(2,2)
  13. \fbox{{\bf x}} A=ones(2,2)-eye(2,2)
  14. \fbox{{\bf x}} A=ones(2,2)-diag(ones(1,2))
  15. \fbox{\phantom{\bf x}} A=matrix([0,1,0,1],2,2)
  16. \fbox{{\bf x}} A=matrix([0,1,1,0],2,2)
  17. \fbox{{\bf x}} A=matrix([0;1;1;0],2,2)
  18. \fbox{\phantom{\bf x}} A=[1,0]*[0;1]+[0,1]*[1;0]
  19. \fbox{{\bf x}} A=[1;0]*[0,1]+[0;1]*[1,0]
  20. \fbox{\phantom{\bf x}} U=ones(2,2); U(1,2)=-1; A=U*diag([1,-1])*U'
  21. \fbox{{\bf x}} U=ones(2,2); U(1,2)=-1; A=U*diag([1,-1])*U'/2
  22. \fbox{\phantom{\bf x}} A=toeplitz(0,1)
  23. \fbox{{\bf x}} A=toeplitz([0,1])
  24. \fbox{\phantom{\bf x}} A=bool2s(eye(2,2)==2);
  25. \fbox{{\bf x}} A=bool2s([1,2;2,3]==2)

Exercice 28   Parmi les lignes de commande suivantes, lesquelles affichent la matrice carrée à dix lignes et dix colonnes A, dont les coefficients d'ordre $ (i,i+1)$ valent $ 1$ pour $ i=1,\ldots,9$ , tous les autres coefficients étant nuls ?
  1. \fbox{\phantom{\bf x}} A=eye(10,10)
  2. \fbox{{\bf x}} A=[zeros(9,1),eye(9,9);zeros(1,10)]
  3. \fbox{\phantom{\bf x}} for i=1:9, A(i,i+1)=1; end; A
  4. \fbox{{\bf x}} A=zeros(10,10); for i=1:9, A(i,i+1)=1; end; A
  5. \fbox{\phantom{\bf x}} for i=1:10, for j=1:10, if j==i+1 then A(i,j)=1;..
    else A(i,j)=0; end; end; A
  6. \fbox{{\bf x}} for i=1:10, for j=1:10, if j==i+1 then A(i,j)=1;..
    else A(i,j)=0; end; end; end; A
  7. \fbox{\phantom{\bf x}} A=toeplitz([0,1,zeros(1,8)])
  8. \fbox{{\bf x}} A=toeplitz(zeros(10,1),[0,1,zeros(1,8)])

Exercice 29   Parmi les lignes de commande suivantes, lesquelles affichent la matrice carrée à dix lignes et dix colonnes A, dont les coefficients d'ordre $ (i,i+1)$ et $ (i+1,i)$ valent $ 1$ pour $ i=1,\ldots,9$ , tous les autres coefficients étant nuls ?
  1. \fbox{\phantom{\bf x}} A=eye(10,10)
  2. \fbox{{\bf x}} A=[zeros(9,1),eye(9,9);zeros(1,10)]; A=A+A'
  3. \fbox{{\bf x}} A=zeros(10,10); for i=1:9, A(i,i+1)=1; A(i+1,i)=1; end; A
  4. \fbox{\phantom{\bf x}} for i=1:10, for j=1:10, if or(j==i+1,j==i-1) then A(i,j)=1;..
    else A(i,j)=0; end; end; A
  5. \fbox{{\bf x}} for i=1:10, for j=1:10, if or([j==i+1,j==i-1]) then A(i,j)=1;..
    else A(i,j)=0; end; end; end; A
  6. \fbox{{\bf x}} for i=1:10, for j=1:10, if j==i+1|j==i-1 then A(i,j)=1;..
    else A(i,j)=0; end; end; end; A
  7. \fbox{\phantom{\bf x}} A=toeplitz([1,zeros(1,9)])
  8. \fbox{{\bf x}} A=toeplitz([0,1,zeros(1,8)])

Exercice 30   Soit $ n$ un entier. Parmi les lignes de commande suivantes, lesquelles affichent le vecteur de taille $ 2n$ dont la coordonnée d'ordre $ 2i$ vaut $ i$ pour $ i=1,\ldots,n$ , les autres coordonnées étant nulles ?
  1. \fbox{{\bf x}} v=zeros(1,2*n); v(2*[1:n])=[1:n]
  2. \fbox{\phantom{\bf x}} v=zeros(1,2*n); v([1:n])=2*[1:n]
  3. \fbox{{\bf x}} v=[zeros(1,n);[1:n]]; v=matrix(v,1,2*n)
  4. \fbox{\phantom{\bf x}} v=[zeros(n,1);[1:n]']; v=matrix(v,1,2*n)
  5. \fbox{\phantom{\bf x}} v=[zeros(1,n);[1:n]]; v=v([1:2*n])
  6. \fbox{{\bf x}} v=[zeros(1,n);[1:n]]'; v=v([1:2*n])
  7. \fbox{{\bf x}} v=[]; for i=1:n, v=[v,0,i]; end; v
  8. \fbox{\phantom{\bf x}} v=[]; for i=1:n, v=[v,[0;i]]; end; v
  9. \fbox{\phantom{\bf x}} v=kron([1:n],[0;1])
  10. \fbox{{\bf x}} v=kron([1:n],[0,1])

Exercice 31   Soit $ n$ un entier. Parmi les lignes de commande suivantes, lesquelles affichent le vecteur de taille $ n$ dont la coordonnée d'ordre $ i$ vaut $ \frac{i(i-1)}{2}$ pour $ i=1,\ldots,n$  ?
  1. \fbox{\phantom{\bf x}} v=[1:n]*[0:n-1]/2
  2. \fbox{{\bf x}} v=[1:n].*[0:n-1]/2
  3. \fbox{{\bf x}} v=[1:n]; v=v.*(v-1)/2
  4. \fbox{\phantom{\bf x}} v=[1:n]; v=v.^2-v/2
  5. \fbox{{\bf x}} v=[1:n]; v=(v.^2-v)/2
  6. \fbox{\phantom{\bf x}} v=cumsum([1:n])
  7. \fbox{{\bf x}} v=cumsum([0:n-1])
  8. \fbox{\phantom{\bf x}} for i=1:n v(i)=i*(i-1)/2; end;
  9. \fbox{{\bf x}} for i=1:n, v(i)=(i^2-i)/2; end; v
  10. \fbox{{\bf x}} v=[]; for i=1:n, v=[v,i*(i-1)/2]; end;

Exercice 32   Soit $ n$ un entier et $ v=(a_1,\ldots,a_n)$ un vecteur ligne d'entiers tous compris entre 0 et $ 9$ . Parmi les lignes de commande suivantes, lesquelles affichent le réel $ x$ , compris entre 0 et $ 1$ dont les $ n$ décimales sont $ (a_1,\ldots,a_n)$  ?
  1. \fbox{\phantom{\bf x}} x=sum(v*10^(-[1:length(v)]))
  2. \fbox{{\bf x}} x=sum(v.*10^(-[1:length(v)]))
  3. \fbox{\phantom{\bf x}} x=sum(v*10^(-[1:size(v)]))
  4. \fbox{{\bf x}} x=sum(v.*10^(-[1:size(v,2)]))
  5. \fbox{{\bf x}} x=sum(v.*10^(-[1:size(v,"*")]))
  6. \fbox{\phantom{\bf x}} s="0"+"."+sum(string(v)); x=evstr(s)
  7. \fbox{{\bf x}} s="0"+"."+strcat(string(v)); x=evstr(s)
  8. \fbox{{\bf x}} x=0; for i=1:length(v), x=x+v(i)*10^(-i); end; x
  9. \fbox{\phantom{\bf x}} x=0; for i=v, x=x+i*10^(-i); end; x
  10. \fbox{\phantom{\bf x}} x=0; d=0.1; for i=v, d=d/10; x=x+i*d; end; x
  11. \fbox{{\bf x}} x=0; d=0.1; for i=v, x=x+i*d; d=d/10; end; x

Exercice 33   Soit $ x$ un réel compris entre 0 et $ 1$ et $ n$ un entier. Parmi les lignes de commande suivantes, lesquelles affichent le vecteur ligne formé des $ n$ premières décimales de $ x$  ?
  1. \fbox{\phantom{\bf x}} v=floor(x*10^[1:n])
  2. \fbox{{\bf x}} v=floor(x*10^[1:n]); v=v-[0,v([1:n-1])]*10
  3. \fbox{\phantom{\bf x}} v=[]; for i=1:n, a=int(x*10^i); v=[v,a]; end;
  4. \fbox{{\bf x}} v=[]; for i=1:n, a=int(x*10); v=[v,a]; x=x*10-a; end; v
  5. \fbox{\phantom{\bf x}} s=string(x); v=[]; for i=1:n, v=[v,part(s,i+2)]; end; v
  6. \fbox{{\bf x}} s=string(x); v=[]; for i=1:n, v=[v,part(s,i+2)]; end; v=evstr(v)

Exercice 34   Soit $ x=(x_i)_{i=1,\ldots,n}$ et $ y=(y_i)_{i=1,\ldots,n}$ deux vecteurs de réels de même taille. Parmi les lignes de commande suivantes lesquelles affichent le calcul de l'intégrale par la méthode des rectangles à droite :

$\displaystyle I = \sum_{i=1}^{n-1} f(x_{i+1})(x_{i+1}-x_i)\;.
$

  1. \fbox{\phantom{\bf x}} n=size(x,"*"); I = sum((x([2:n])-x([1:n-1]))*y([2:n]))
  2. \fbox{{\bf x}} n=size(x,"*"); I = sum((x([2:n])-x([1:n-1])).*y([2:n]))
  3. \fbox{\phantom{\bf x}} n=size(x,"*"); I = sum((x([2:n])-x([1:n-1]))*y([1:n-1]))
  4. \fbox{\phantom{\bf x}} I=0; for i=1:length(x), I = I+(x(i+1)-x(i))*y(i+1); end; I
  5. \fbox{{\bf x}} I=0; for i=2:length(x), I = I+(x(i)-x(i-1))*y(i); end; I
  6. \fbox{{\bf x}} I=0; for i=1:length(x)-1, I = I+(x(i+1)-x(i))*y(i+1); end; I

Exercice 35   Soit $ z$ un nombre complexe non nul. Parmi les lignes de commande suivantes, lesquelles affichent l'argument de $ z$ (réel $ t$ dans $ [0,2\pi[$ tel que $ z=\vert z\vert e^{i t}$ ) ?
  1. \fbox{\phantom{\bf x}} t=argn(z)
  2. \fbox{\phantom{\bf x}} t=phasemag(z)
  3. \fbox{{\bf x}} t=%phasemag(z)/180*%pi
  4. \fbox{\phantom{\bf x}} t=log(z/abs(z))/%i
  5. \fbox{\phantom{\bf x}} t=imag(log(z/abs(z)))
  6. \fbox{{\bf x}} t=imag(log(z/abs(z))); if imag(z)<0 then t=t+2*%pi; end; t
  7. \fbox{\phantom{\bf x}} t=acos(real(z)/abs(z))
  8. \fbox{{\bf x}} t=acos(real(z)/abs(z)); if imag(z)<0 then t=-t+2*%pi; end; t
  9. \fbox{\phantom{\bf x}} t=asin(imag(z)/abs(z))
  10. \fbox{\phantom{\bf x}} t=asin(imag(z)/abs(z)); if imag(z)<0 then t=-t+2%pi; end; t
  11. \fbox{\phantom{\bf x}} t=atan(imag(z)/real(z))

Exercice 36   Soit $ P(X)=a_0+a_1X+\cdots+a_nX^n$ un polynôme. Parmi les lignes de commande suivantes, lesquelles affichent le polynôme réciproque $ Q(X)=a_n+a_{n-1}X+\cdots+a_0X^n$  ?
  1. \fbox{\phantom{\bf x}} Q=X^degree(P)*horner(P,1/X)
  2. \fbox{{\bf x}} X=poly([0,1],"X","coeff"); Q=X^degree(P)*horner(P,1/X)
  3. \fbox{\phantom{\bf x}} c=coeff(P); c=c([length(c):-1:1]); Q=poly(c,"X");
  4. \fbox{{\bf x}} c=coeff(P); c=c([length(c):-1:1]); Q=poly(c,"X","coeff")
  5. \fbox{\phantom{\bf x}} r=roots(P); Q=poly(1/r,"X")
  6. \fbox{{\bf x}} r=roots(P); c=coeff(P); Q=c($)*poly((1)./r,"X")*prod(r)*(-1)^degree(P)

Exercice 37   Parmi les lignes de commande suivantes, lesquelles affichent un segment de droite d'une seule couleur ?
  1. \fbox{\phantom{\bf x}} plot2d([0,1],[0,1],-5)
  2. \fbox{{\bf x}} plot2d([0,1],[0,1],5)
  3. \fbox{\phantom{\bf x}} x=[0:0.1:1]; plot2d(x,x,0)
  4. \fbox{\phantom{\bf x}} x=[0:0.1:1]; plot2d2(x,x)
  5. \fbox{\phantom{\bf x}} x=[0:0.1:1]; plot2d3(x,x)
  6. \fbox{\phantom{\bf x}} x=[0,0.5;0.5,1]; plot2d(x,x)
  7. \fbox{{\bf x}} x=[0,0.5;0.5,1]; plot2d(x,x,[5,5])

Exercice 38   Parmi les lignes de commande suivantes, lesquelles affichent un losange ?
  1. \fbox{{\bf x}} x=[-1;0;1]; y=[0;1;0]; plot2d([x,x],[y,-y],[1,1])
  2. \fbox{\phantom{\bf x}} x=[-1,0,1]; y=[0,1,0]; plot2d([x;x],[y;-y],[1,1])
  3. \fbox{\phantom{\bf x}} plotframe([-1,-1,1,1],[10,1,10,1]); x=[0,1,0,-1]; y=[-1,0,1,0]; xpoly(x,y)
  4. \fbox{{\bf x}} plotframe([-1,-1,1,1],[10,1,10,1]);
    x=[0,1,0,-1]; y=[-1,0,1,0]; xpoly(x,y,"lines",1)
  5. \fbox{{\bf x}} plotframe([-1,-1,1,1],[10,1,10,1]);
    x=[0,1,0,-1,0]; y=[-1,0,1,0,-1]; xpoly(x,y)

Exercice 39   On suppose que les échelles en abscisse et ordonnée ont été fixées par la commande
isoview(-1,1,-1,1). Parmi les lignes de commande suivantes, lesquelles affichent un cercle ?
  1. \fbox{{\bf x}} x=linspace(-1,1,200)'; y=sqrt(1-x.^2); plot2d([x,x],[y,-y],[5,5])
  2. \fbox{\phantom{\bf x}} x=[-1:1]'; y=sqrt(1-x.^2); plot2d([x,x],[y,-y],[5,5])
  3. \fbox{\phantom{\bf x}} x=linspace(-1,1,200)';y=sqrt(1-x.^2);plot2d([x;x],[y;-y],[5,5])
  4. \fbox{{\bf x}} t=linspace(0,2*%pi); x=cos(t); y=sin(t); plot2d(x,y)
  5. \fbox{\phantom{\bf x}} xarc(-1,1,2,2,0,2*%pi)
  6. \fbox{{\bf x}} plotframe([-1,-1,1,1],[10,1,10,1]); xarc(-1,1,2,2,0,360*64)
  7. \fbox{{\bf x}} plot2d(0,0); xarc(-1,1,2,2,0,360*64)

Exercice 40   Parmi les lignes de commande suivantes, lesquelles affichent une représentation graphique satisfaisante de la fonction $ f(x)=\frac{1}{\sin(x)}$ , pour $ x\in [0,2\pi]$  ?
  1. \fbox{{\bf x}} plotframe([0,-10,2*%pi,10],[10,1,10,1])
    e=0.1; x=linspace(e,%pi-e,200); y=(1)./sin(x); plot2d(x,y,5,"000");
    e=0.1; x=linspace(%pi+e,2*%pi-e,200); y=(1)./sin(x); plot2d(x,y,5,"000");
  2. \fbox{\phantom{\bf x}} e=0.1; x=linspace(e,%pi-e,200); y=(1)./sin(x); plot2d(x,y,5);
    e=0.1; x=linspace(%pi+e,2*%pi-e,200); y=(1)./sin(x); plot2d(x,y,5,"000");
  3. \fbox{{\bf x}} e=0.1; x=linspace(e,%pi-e,200); x=[x',x'+%pi]; y=(1)./sin(x);
    plot2d(x,y,[5,5]);
  4. \fbox{\phantom{\bf x}} e=0.01; x=[e:e:%pi-e]; x=[x',x'+%pi]; y=(1)./sin(x);
    plot2d(x,y,[5,5]);

Exercice 41   On souhaite définir la fonction $ f$ qui prenne en entrée une matrice quelconque x, et qui retourne la matrice des images des coefficients de x par la fonction $ f(x)=\frac{1}{e^x\sin(x)}$ . Parmi les lignes de commande suivantes, lesquelles sont correctes ?
  1. \fbox{\phantom{\bf x}} deff("y=f(x)","y=1/(exp(x)*sin(x))")
  2. \fbox{{\bf x}} deff("y=f(x)","y=(1)./(exp(x).*sin(x))")
  3. \fbox{\phantom{\bf x}} deff("y=f(x)","y=1./(%e^x.*sin(x))")
  4. \fbox{{\bf x}} deff("y=f(x)","y=(1)./(%e^x.*sin(x))")
  5. \fbox{{\bf x}} deff("y=f(x)","y=exp(-x)./sin(x)")
  6. \fbox{\phantom{\bf x}} function y=f(x) y=(1)./(%e^x.*sin(x)) endfunction
  7. \fbox{{\bf x}} function y=f(x)
    y=(1)./(%e^x.*sin(x))
    endfunction



suivant: Index monter: CN_ECS précédent: Exercices   Table des matières   Index
Georges Koepfler 2011-01-19