Klausur - Lösung
Contents
Called Functions
Mit Tests für jeden Aufgabenteil. Lösung ist am Ende zu finden.
A1a)
clear all; close all; disp(aufgabe1(4)) disp(aufgabe1(5.8)) disp(aufgabe1(6.1))
-2 1 0 1 1 -2 1 0 0 1 -2 1 1 0 1 -2 Achtung: Nur natürliche Zahlen sind zulässig. Runde ab. -2 1 0 0 1 1 -2 1 0 0 0 1 -2 1 0 0 0 1 -2 1 1 0 0 1 -2 Achtung: Nur natürliche Zahlen sind zulässig. Runde ab. -2 1 0 0 0 1 1 -2 1 0 0 0 0 1 -2 1 0 0 0 0 1 -2 1 0 0 0 0 1 -2 1 1 0 0 0 1 -2
A2a)
clear all; close all; f=@(x) 71-6*x^2+0.4*x^3; x0=0;x1=3; [x,n,err]=aufgabe2(f,x0,x1,1.e-12); disp(['x = ' num2str(x) ', n = ' num2str(n) ', err = ' num2str(err)]) x0=10;x1=13; [x,n,err]=aufgabe2(f,x0,x1,1.e-12); disp(['x = ' num2str(x) ', n = ' num2str(n) ', err = ' num2str(err)]) x0=-100;x1=-102; [x,n,err]=aufgabe2(f,x0,x1,1.e-12); disp(['x = ' num2str(x) ', n = ' num2str(n) ', err = ' num2str(err)]) disp(' ')
x = 4.0208, n = 6, err = 6.97e-11 x = 14.1082, n = 8, err = 1.3678e-13 x = -3.129, n = 16, err = 1.684e-09
b)
help aufgabe2
[x, n, e] = aufgabe2(f,x0,x1,tol) Funktion zur Iterativen Bestimmung von Nullstellen. Abbruch nach max. 1000 Iterationen. Input: f => Funktion x0, x1 => Startwerte tol => Toleranz Output: x => Nullstelle n => Anz. Itarationen e => Fehler Published output in the Help browser showdemo aufgabe2
A3a)
clear all; close all; disp(aufgabe3a(44,4))
-8.4004e+18
b)
disp(aufgabe3b(43,-6))
1.3210e+18
c)
aufgabe3c
A4a)
clear all; close all; disp(aufgabe4a(6,5))
35429
b)
disp(aufgabe4b(6,5))
5905
c)
clear all; close all; aufgabe4c
A5a)
name = aufgabe5a('vornamen.txt'); disp([name{2} ' ' name{4} ' ' name{5}])
Wolfgang Werner Klaus
b)
clear all; close all; aufgabe5b disp(' ') % open the file fid = fopen('liste.txt'); tline = fgetl(fid); i=1; while ischar(tline) if 1 == mod(i,8) disp([sscanf(tline, '%s%') ' ' sscanf(tline, '%*s %s%') ' '... sscanf(tline, '%*s %*s %s%') ' ' sscanf(tline, '%*s %*s %*s %s')]) end tline = fgetl(fid); i=i+1; end % close the file fclose(fid);
Student/in Mat.Nr. Note Schulz Peter 866930 1.3 Wagner Wolfgang 484480 1.7 Weber Michael 694752 3.7 Schneider Werner 451739 3.0 Bauer Werner 126500 1.3 Schulz Klaus 913800 3.3 Wagner Maria 154370 2.3 Weber Ursula 558319 3.3 Schneider Monika 743688 1.3 Bauer Monika 679734 1.0 Schulz Petra 163512 4.0 Wagner Elisabeth 317428 3.7