Laborator - Metode - Numerice - Colocviu - Laborator - Cunosti Nte - Necesare - Minime PDF
Laborator - Metode - Numerice - Colocviu - Laborator - Cunosti Nte - Necesare - Minime PDF
Laborator - Metode - Numerice - Colocviu - Laborator - Cunosti Nte - Necesare - Minime PDF
>> b=ones(2,5)
b=
1
1
1
1
1
1
1
1
>> I=eye(4)
I=
1 0 0
0 1 0
0 0 1
0 0 0
0
0
0
1
1
1
Manipularea matricelor:
Accesarea elementelor unei matrice:
>> I(2,3)
ans =
0
Lucrul cu diagonalele unei matrice:
>> a=[3 5 4 3 ;5 4 3 5;6 5 3 4;6 5 2 7]
a=
3 5 4 3
5 4 3 5
6 5 3 4
6 5 2 7
>> d=diag(a)
d=
3
4
3
7
>> d=diag(a,2)
d 1=
4
5
>> d=diag(a,-2)
22 =
6
5
Crearea unei matrice cu diagonala cunoscuta:
>> D=diag([3 5 3 2 5])
D=
3 0 0 0 0
0 5 0 0 0
0 0 3 0 0
0
0
0
0
0
0
2
0
0
5
Operatii cu matrice:
>> a=[4 3 5;6 5 3;7 5 2]
a=
4 3 5
6 5 3
7 5 2
>> b=[5 1 5;7 4 2;7 3 9]
b=
5 1 5
7 4 2
7 3 9
>> a+b
ans =
9 4 10
13 9 5
14 8 11
>> a-b
ans =
-1 2 0
-1 1 1
0 2 -7
>> a*b
ans =
76 31 71
86 35 67
84 33 63
>> 3*a
ans =
12 9 15
18 15 9
21 15 6
>> a/b
ans =
-0.9394
-1.3030
-0.7424
>> a\b
ans =
0.2222
1.0000
0.2222
0.2121 1.0303
0.9394 0.8485
1.1515 0.3788
-1.2778 7.2778
2.5000 -8.5000
-0.2778 0.2778
Analiza matriceala:
6.2832
>> sin(x)
ans =
-2.4493e-016
>> cos(x)
ans =
1
>> tan(x)
ans =
-2.4493e-016
>> cot(x)
ans =
-4.0828e+015
>> asin(0.5)
ans =
0.5236
>> acos(0.7)
ans =
0.7954
>> plot(x,y,x,y,'o')
3
2
1
>> b=[1; 2; 5]
b=
1
2
5
Testare solutie sistem:
>> det(A)
ans =
-2.0000
Rezolvare prin impartire la stanga:
>> x=A\b
x=
-4.0000
10.0000
-5.0000
0
0
Factorizare Choleski:
1
>> det(A(1:3,1:3))
ans =
2
Factorizare Choleski:
>> [R,p]=chol(A)
R=
1.0000 2.0000 1.0000
0 1.0000
0
0
0 1.4142
p=
0
Rezolvare sisteme: R*y=b si RU*x=y
>> y=R'\b
y=
5.0000
1.0000
1.4142
>> x=R\y
x=
2.0000
1.0000
1.0000
4. Aproximarea functiilor (Lucrarile de laborator nr. 9, 10 din indrumar)
- interpolare liniara: calculare valori ale functiilor in anumite punte in intervalul specificat
>> x=[1 2 3 4 5 6 7]
x=
1 2 3 4 5 6 7
>> y=[-10 -6 -3 -2 4 9 21]
y=
-10 -6 -3 -2 4 9 21
>> interp1(x,y,[1.5 2.6 4.2 6.8])
ans =
-8.0000 -4.2000 -0.8000 18.6000
Reprezentarea grafica a interpolarii liniare
- interpolare spline: calculare valori ale functiilor in anumite punte in intervalul specificat
>> x=[1 2 3 4 5 6 7]
x=
1 2 3 4 5 6 7
>> y=[-10 -6 -3 -2 4 9 21]
y=
-10 -6 -3 -2 4 9 21
>> spline(x,y,[1.5 2.6 4.2 6.8])
ans =
-8.1451 -3.8034 -1.1074 17.4246
Reprezentare grafica:
r2 =
0.7143 -1.0714 -8.1429
>> r3=polyfit(x,y,3)
r3 =
0.2500 -2.2857 9.1786 -17.1429
Reprezentare grafica:
>> xi=1:0.01:7;
>> y2=polyval(r2,xi);
>> y3=polyval(r3,xi);
>> plot(x,y,'o',xi,y2,xi,y3)
5. Integrare, Derivare
- metoda trapezelor
Pentru functii direct tabelate
>> x=[1 2 3 4 5 6 7]
x=
1 2 3 4 5 6 7
>> y=[-10 -6 -3 -2 4 9 21]
y=
-10 -6 -3 -2 4 9 21
>> I=trapz(x,y)
I=
7.5000
Pentru functii analitice:
>> f=inline('x.^3-3*x+1')
f=
Inline function:
f(x) = x.^3-3*x+1
>> x=1:0.01:4;
>> y=f(x);
>> I=trapz(x,y)
I=
44.2504
- metoda Simpson
>> f=inline('x.^3-3*x+1')
f=
Inline function:
f(x) = x.^3-3*x+1
>> I=quad(f,1,4)
I=
44.2500
- derivata unei functii
Functie tabelata:
>> x=[1 2 3 4 5 6 7]
x=
1 2 3 4 5 6 7
>> y=[-10 -6 -3 -2 4 9 21]
y=
-10 -6 -3 -2 4 9 21
>> dx=diff(x)
dx =
1 1 1 1 1 1
>> dy=diff(y)
dy =
4 3 1 6 5 12
Diferente finite la stanga / dreapta
>> df=dy./dx
df =
4 3 1 6 5 12
Diferente centrate:
>> k=length(dx)
k=
6
>> dfc=(dy(1:k-1)+dy(2:k))./(dx(1:k-1)+dx(2:k))
dfc =
3.5000 2.0000 3.5000 5.5000 8.5000
- derivata unui polinom polyder
Definirea sirului de coeficienti ai ecuatiei: Ex.
>> c=[1 0 0 1 3 0 -10 0 -3]
c=
1 0 0 1 3 0 -10 0 -3
Calculul derivatei cu functia polyder:
>> d=polyder(c)
d=
8 0 0 5 12 0 -20 0