TU Wien:Computernumerik VU (Schranz-Kirlinger)/Übungen SS16/Beispiel 4
Zur Navigation springen
Zur Suche springen
Lösung[Bearbeiten | Quelltext bearbeiten]
Matlab Code
function [ ] = bsp4()
y1 = (1-0.9)^6;
y2 = 1-6*0.9+15*0.9^2-20*0.9^3+15*0.9^4-6*0.9^5+0.9^6;
y3 = 1+0.9*(-6+0.9*(15+0.9*(-20+0.9*(15+0.9*(-6+0.9)))));
sprintf('%s %0.25f %s %0.25f %s %0.25f','y1 = ', y1, 'y2 = ', y2, 'y3 = ', y3)
relError1a = abs((10^-6 - y1)/10^-6);
relError1b = abs(1-(10^6*y1));
relError2a = abs((10^-6 - y2)/10^-6);
relError2b = abs(1-(10^6*y2));
relError3a = abs((10^-6 - y3)/10^-6);
relError3b = abs(1-(10^6*y3));
sprintf('%s %0.15f %0.15f','rel. Error y1 = ', relError1a, relError1b)
sprintf('%s %0.15f %0.15f','rel. Error y2 = ', relError2a, relError2b)
sprintf('%s %0.15f %0.15f','rel. Error y3 = ', relError3a, relError3b)
end