TD Matlab
TD Matlab
TD Matlab
A=
3 -1 0
0 1 0
0 0 2
B=
3 5 1
7 -2 4
-6 3 2
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 +
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
>> 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 =
>> y=A*C
>> y=A*c
y=
>> X=inv(A)*b
>>EXO 6
A=
1 2 3
2 3 1
3 1 2
ans =
2 1
3 2
2 3
3 1
ans =
2 3 1
3 1 2
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
>> 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
>>
A=
10 7 8 7
7 5 6 5
8 6 10 9
7 5 9 10
>> b1 =
32
23
33
31
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=
>> inv(A)
ans =
>> eye(A)
>> inv(A)*A
ans =
>> [L,U,P]=lu(A,1)
Error using lu
>> [L,U,P]=lu(A)
L=
1.0000 0 0 0 0 0 0
0.1390 1.0000 0 0 0 0 0
U=
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
det(A)=prod(diag(U))*(1)^P
>> [piv,L,U]=lu(A)
piv =
1.0000 0 0 0 0 0 0
0.1390 1.0000 0 0 0 0 0
L=
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.')
>> gtext('y=x')
>> gtext('y=-x')
>> gtext('y=x*sin(1/x)')
>>