TU Wien:Computernumerik VU (Schranz-Kirlinger)/Übungen SS16/Beispiel 15
Lösung[Bearbeiten | Quelltext bearbeiten]
Matlab Code
function Bsp5
%% a)
Aex =[1.253672417 1.247798111 ; -2.672344812 2.695328007];
bex =[3.654199872 2.479981003]';
xex = Aex\bex;
fprintf('%s %0.15f %s %0.15f\n','correct x1 = ', xex(1), 'x2 = ', xex(2));
Af=[1.253672000 1.247798000 ; -2.672344000 2.695328000];
bf=[3.654199000 2.479981000]';
xf=Af\bf;
fprintf('%s %0.15f %s %0.15f\n','false x1 = ', xf(1), 'x2 = ', xf(2));
%kappa_2 and kappa_inf
kappa2 = cond(Aex,2);
kappainf = cond(Aex,inf);
fprintf('%s %0.15f %s %0.15f\n', 'kappa_2 = ', kappa2, 'kappa_inf = ', kappainf);
%% b)
Aex=[1.743681226 -0.5287326143 ; 4.359203065 -1.321302803];
bex=[2.666771987 6.667195145]';
xex=Aex\bex;
fprintf('%s %0.15f %s %0.15f\n','correct x1 = ', xex(1), 'x2 = ', xex(2));
Af=[1.743681000 -0.5287326000 ; 4.359203000 -1.321302000];
bf=[2.666771000 6.667195000]';
xf=Af\bf;
fprintf('%s %0.15f %s %0.15f\n','false x1 = ', xf(1), 'x2 = ', xf(2));
%kappa_2 and kappa_inf
kappa2 = cond(Aex,2);
kappainf = cond(Aex,inf);
fprintf('%s %0.15f %s %0.15f\n', 'kappa_2 = ', kappa2, 'kappa_inf = ', kappainf);
end