3. laborgyakorlat, házik megoldásai
Contents
clear all, close all
1. feladat
A=[24,-32;31,-41], b=[40;53]
x=A\b
A =
24 -32
31 -41
b =
40
53
x =
7
4
2. feladat
kondicioszam=cond(A)
A=[24,-32;31,-41], bnew=[40;53.1]
xnew=A\bnew
bvalt=norm(bnew-b)/norm(b)*100
xvalt=norm(xnew-x)/norm(x)*100
arany=xvalt/bvalt
kondicioszam =
530.2481
A =
24 -32
31 -41
bnew =
40.0000
53.1000
xnew =
7.4000
4.3000
bvalt =
0.1506
xvalt =
6.2017
arany =
41.1797
3. feladat
A=rand(1000); b=rand(1000,1);
B=A'*A;
tic, A\b; toc
tic, B\b; toc
Elapsed time is 0.580604 seconds.
Elapsed time is 0.345811 seconds.
4. feladat
L=[1,0,0,0;2,1,0,0;3,2,1,0;1,-1,2,1]
U=[2,1,-1,1;0,3,2,1;0,0,4,2;0,0,0,5]
b=[3;12;27;14]
A=L*U
x=A\b
L =
1 0 0 0
2 1 0 0
3 2 1 0
1 -1 2 1
U =
2 1 -1 1
0 3 2 1
0 0 4 2
0 0 0 5
b =
3
12
27
14
A =
2 1 -1 1
4 5 0 3
6 9 5 7
2 -2 5 9
x =
1.0000
1.0000
1.0000
1.0000