>> EXERCICE3
A=[3 -1 0;0 1 0;0 0 2]
A=
3 -1 0
0 1 0
0 0 2
>> B=[3 5 1;7 -2 4;-6 3 2]
B=
3 5 1
7 -2 4
-6 3 2
>> C=[5 6 5;6 10 9;5 9 10]
C=
5 6 5
6 10 9
5 9 10
>> a=eig(A)
a=
>> b=eig(B)
b=
-7.3538 + 0.0000i
5.1769 + 2.0832i
5.1769 - 2.0832i
>> c=eig(C)
c=
0.5660
1.9659
22.4681
>> [V,L]=eig(A)
V=
1.0000 0.4472 0
0 0.8944 0
0 0 1.0000
L=
3 0 0
0 1 0
0 0 2
>> [V,L]=eig(A)
V=
1.0000 0.4472 0
0 0.8944 0
0 0 1.0000
L=
3 0 0
0 1 0
0 0 2
>> A+C
ans =
8 5 5
6 11 9
5 9 12
>> A*C
ans =
9 8 6
6 10 9
10 18 20
>> A.*C
ans =
15 -6 0
0 10 0
0 0 20
>> v=[1;2;3]
v=
>> R=A+v
Error using +
Matrix dimensions must agree.
>> B=[3 5 1 1;7 -2 4 2;-6 3 2 3]
B=
3 5 1 1
7 -2 4 2
-6 3 2 3
>> k=null(B)
k=
0.1191
-0.0959
-0.6349
0.7573
>>EXERCICE4
>> A=[2 1 -3;1 -2 1];
>> b=[1 2]';
>> rank(A)
ans =
2
>> B=[2 1 -3 1;1 -2 1 2]
B=
2 1 -3 1
1 -2 1 2
>> rank(B)
ans =
>> c=[1 1 1]';
>> y=A*C
Undefined function or variable 'C'.
Did you mean:
>> y=A*c
y=
>> X=inv(A)*b
Error using inv
Matrix must be square.
>>EXO 6
>> A=[1 2 3;2 3 1;3 1 2]
A=
1 2 3
2 3 1
3 1 2
>> A([2 3],[1 3])
ans =
2 1
3 2
>> A([2 3],1:2)
ans =
2 3
3 1
>> A([2 3],:)
ans =
2 3 1
3 1 2
>> A([2 3],end)
ans =
>> A(:)
ans =
>> A(5)
ans =
>> reshape(A(:),size(A))
ans =
1 2 3
2 3 1
3 1 2
>>>> % EXO7
>> A=[1 2 3; 2 3 1;3 1 2]
A=
1 2 3
2 3 1
3 1 2
>> C=[A,zeros(3,2);zeros(2,3),eye(2)]
C=
1 2 3 0 0
2 3 1 0 0
3 1 2 0 0
0 0 0 1 0
0 0 0 0 1
>>>> TP1
1)
>> A=magic(5)
A=
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> sum_lignes=sum(A,2)
sum_lignes =
65
65
65
65
65
>> sum_colonnes=sum(A,1)
sum_colonnes =
65 65 65 65 65
>> sum_diagonale1=sum(diag(A))
sum_diagonale1 =
65
>> sum_diagonale2=sum(diag(fliplr(A)))
sum_diagonale2 =
65
>> A(3,:)
ans =
4 6 13 20 22
>> A(1,2)
ans =
24
>>2)
>> p=[3 -1 7]
p=
3 -1 7
>> roots(p)
ans =
0.1667 + 1.5184i
0.1667 - 1.5184i
>>
>> %plus a propose des matrices et tableaux
>> A=[10 7 8 7;7 5 6 7;8 6 10 9;7 5 9 10]
A=
10 7 8 7
7 5 6 5
8 6 10 9
7 5 9 10
>> b1=[32 23 33 31]'
>> b1 =
32
23
33
31
>> b2=[32.1 22.9 33.1 30.9]'
b2 =
32.1
22.9
33.1
30.9
>> x=inv(A)*b1
x=
1.000
1.000
1.000
1.000
>> x2=inv(A)*b2
x2 =
4.9048
-5.4762
2.7190
-0.0524
>> y=eig(A)
y=
30.6789
3.3601
0.3157
0.6453
>> >>TP4
>> A=rand(7)
A=
0.8147 0.5469 0.8003 0.0357 0.6555 0.8235 0.7655
0.9058 0.9575 0.1419 0.8491 0.1712 0.6948 0.7952
0.1270 0.9649 0.4218 0.9340 0.7060 0.3171 0.1869
0.9134 0.1576 0.9157 0.6787 0.0318 0.9502 0.4898
0.6324 0.9706 0.7922 0.7577 0.2769 0.0344 0.4456
0.0975 0.9572 0.9595 0.7431 0.0462 0.4387 0.6463
0.2785 0.4854 0.6557 0.3922 0.0971 0.3816 0.7094
>> inv(A)
ans =
0.2150 0.3124 -0.5303 0.2803 0.9697 -0.5554 -0.7391
0.7551 0.6244 -0.6416 -0.6979 0.1878 1.9664 -2.7736
0.1938 -0.8510 -0.1891 0.3615 0.4972 0.4637 -0.1897
-1.2070 -0.0659 0.9475 0.6014 -0.0246 -1.1940 1.8149
0.2754 -0.5342 1.2076 -0.1488 -0.0479 -1.5358 1.5155
0.5698 0.4188 0.0176 0.3729 -1.2926 1.4092 -1.8184
-0.4570 0.1211 0.1233 -0.4794 -0.2533 -1.4436 3.5402
>> eye(A)
Error using eye
N-dimensional arrays are not supported.
>> inv(A)*A
ans =
1.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000
0.0000 1.0000 0.0000 -0.0000 0.0000 0.0000 0.0000
-0.0000 -0.0000 1.0000 0.0000 0.0000 0.0000 -0.0000
-0.0000 -0.0000 -0.0000 1.0000 -0.0000 -0.0000 -0.0000
0.0000 -0.0000 -0.0000 -0.0000 1.0000 -0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 0.0000
-0.0000 0.0000 -0.0000 0.0000 -0.0000 -0.0000 1.0000
>> [L,U,P]=lu(A,1)
Error using lu
Permutation flag must be 'matrix' or 'vector'.
>> [L,U,P]=lu(A)
L=
1.0000 0 0 0 0 0 0
0.1390 1.0000 0 0 0 0 0
0.9917 0.8497 1.0000 0 0 0 0
0.8920 0.4309 0.1411 1.0000 0 0 0
0.1068 0.9972 -0.5589 0.5457 1.0000 0 0
0.6923 0.9136 0.1090 0.4916 0.4693 1.0000 0
0.3049 0.4638 -0.2361 0.3868 0.4414 0.0716 1.0000
U=
0.9134 0.1576 0.9157 0.6787 0.0318 0.9502 0.4898
0 0.9430 0.2944 0.8396 0.7016 0.1850 0.1188
0 0 -1.0164 -0.5374 -0.4565 -0.4047 0.2086
0 0 0 -0.8557 0.3892 -0.0467 0.2480
0 0 0 0 -1.1244 -0.0479 0.4568
0 0 0 0 0 -0.7029 -0.3610
0 0 0 0 0 0 0.2825
P=
0 0 0 1 0 0 0
0 0 1 0 0 0 0
0 1 0 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 1 0
0 0 0 0 1 0 0
0 0 0 0 0 0 1
>> det(A)=prod(diag(U))*(-1)^P
Subscript indices must either be real positive integers or logicals.
det(A)=prod(diag(U))*(1)^P
Subscript indices must either be real positive integers or logicals.
>> [piv,L,U]=lu(A)
piv =
1.0000 0 0 0 0 0 0
0.1390 1.0000 0 0 0 0 0
0.9917 0.8497 1.0000 0 0 0 0
0.8920 0.4309 0.1411 1.0000 0 0 0
0.1068 0.9972 -0.5589 0.5457 1.0000 0 0
0.6923 0.9136 0.1090 0.4916 0.4693 1.0000 0
0.3049 0.4638 -0.2361 0.3868 0.4414 0.0716 1.0000
L=
0.9134 0.1576 0.9157 0.6787 0.0318 0.9502 0.4898
0 0.9430 0.2944 0.8396 0.7016 0.1850 0.1188
0 0 -1.0164 -0.5374 -0.4565 -0.4047 0.2086
0 0 0 -0.8557 0.3892 -0.0467 0.2480
0 0 0 0 -1.1244 -0.0479 0.4568
0 0 0 0 0 -0.7029 -0.3610
0 0 0 0 0 0 0.2825
U=
0 0 0 1 0 0 0
0 0 1 0 0 0 0
0 1 0 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 1 0
0 0 0 0 1 0 0
0 0 0 0 0 0 1
b=[1 2 3 4 5 6 7]';
y=zeros(size(b));
x=zeros(size(b));
%Foward substitution
for i=1:size(A,1)
y(i)=b(piv(i));
for j=1:i-1
y(i)=y(i)-L(i,j)*y(j);
end
end
TP2
1)
x=linspace(-2,2);
y=exp(x);
plot(x,y);
grid on
title('courbe exp(x)')
xlabel('x');
ylabel('y');
2)
R=3;
w=linspace(0,3*R);
x=R*(w-sin(w));
y=R*(1-cos(w));
plot(x,y);
hold on
grid on
xlabel('x')
ylabel('y')
title('trace de la courbe en cycloide');
3)
x=linspace(-10,10);
y=linspace(-10,10);
r=sqrt(x.*x+y.*y);
z=10.*cos(r)./r+2;
plot3(x,y,z)
grid('on')
hold('on')
xlabel('X')
ylabel('Y')
zlabel('Z')
title('trace de la courbe 3D')
3)
x=linspace(-0.1,0.1);
v=x.*sin(1./x);
>> plot(x,v,'r');
>> grid on
>> hold on
>> plot(x,-x,'b.')
plot(x,x,'b.')
>> xlabel('axe des x')
>> ylabel('axe des y')
>> gtext('y=x')
>> gtext('y=-x')
>> gtext('y=x*sin(1/x)')
>>