algorithmen zur datenanalyse in c++ fileeinführung standard library numerische integration...
TRANSCRIPT
![Page 1: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/1.jpg)
Einführung Standard Library Numerische Integration
Algorithmen zur Datenanalyse in C++
Hartmut Stadie
21.05.2012
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 1/ 21
![Page 2: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/2.jpg)
Einführung Standard Library Numerische Integration
Einführung
Standard Library
Numerische Integration
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 2/ 21
![Page 3: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/3.jpg)
Einführung Standard Library Numerische Integration
Übersicht
EinführungInformationen
Standard Library
Numerische Integration
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 3/ 21
![Page 4: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/4.jpg)
Einführung Standard Library Numerische Integration
Informationen
Ablauf:Vorlesung: montags 16:00 Hörsaal IIIÜbung: im Anschluss an die Vorlesung in 9/302 und 9/305
Material:Stroustrup: The C++ Programming Language, 3rd editionhttp://www.lernnetz-sh.de/kmLinux/doc/C++-Kurs/index.htmlhttp://www.highscore.de/cpp/einfuehrung/Press et al: Numerical Recipes, 3rd editionhttp://wwwiexp.desy.de/studium/lehre/cplusplus/
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 4/ 21
![Page 5: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/5.jpg)
Einführung Standard Library Numerische Integration
Übersicht
Einführung
Standard LibraryStringsContainer
OperationenAlgorithmen
Numerische Integration
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 5/ 21
![Page 6: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/6.jpg)
Einführung Standard Library Numerische Integration
Standard Library
Die C++ Standardbibliothek:unterstützt Spracheigenschaften wie Speicherverwaltungund Laufzeittypinformationgibt Informationen über Aspekte derSprachimplementation, max(float)Funktionen, die nicht direkt für jedes System in derSprache implementiert werden können: sqrtKomplexe Werkzeuge, die dem Programmierer auf jedemSystem zur Verfügung stehen: Listen, Maps,Sortierfunktionen, I/O streamserlaubt diese Werkzeuge zu erweiternFundament für weitere Bibliotheken
Alle Funktionen, Klassen im Namensraum std.Algorithmen zur Datenanalyse in C++ Hartmut Stadie 6/ 21
![Page 7: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/7.jpg)
Einführung Standard Library Numerische Integration
Strings
Text schwierig in C++Lösung: stringKonstruktoren:
string s = "Hartmut";string s2(s,0,4);//Hartstring s3(5,’h’);//hhhhh
Zuweisung:
string s = "Hartmut";string t;t=s;s[2] = ’u’;
C-style Strings:
const char* text = s.c_str();
Speicher gehört string!einzelne Buchstaben:
char c3 = s[3];char c4 = s.at(3);
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 7/ 21
![Page 8: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/8.jpg)
Einführung Standard Library Numerische Integration
StringsVergleich:
if(s == "Hans") { }
Verketten:
s2 = "Welt";s += ’ ’;s.append(s2);s.insert(7," ");
Finden, Löschen und Ersetzen:
string s("Hartmut");string::size_type pos_a = s.find(’a’);string::size_type pos_mut = s.find("mut");string::size_type pos_t2 = s.rfind(’t’);string::size_type npos = s.length();if(pos_t2 < npos) ...s.erase(pos_t2,1);s.replace(pos_a,1,’u’);
Beispiel: string.cxxAlgorithmen zur Datenanalyse in C++ Hartmut Stadie 8/ 21
![Page 9: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/9.jpg)
Einführung Standard Library Numerische Integration
Container
Probleme mit Feldern in C++feste GrößeFehlerquelle: new/delete
Lösung: STL ContainerDokumentation: http://www.sgi.com/tech/stl/Beispiel: Wörter einlesen, Buchstaben zählen(stl.cxx)
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 9/ 21
![Page 10: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/10.jpg)
Einführung Standard Library Numerische Integration
Operationen
Iteratoren:
for(vector::iterator i = v.begin(); v != v.end() ; ++i) {i->print();//oder (*i).print();
}
Elementzugriff:
front();back();[];at();
Stapel- und Queueoperationen:
push_back();pop_back();push_front();pop_front();
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 10/ 21
![Page 11: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/11.jpg)
Einführung Standard Library Numerische Integration
Operationen II
Listenoperationen:
insert(p,x);erase(p);clear();
andere Operationen:
size();empty();capacity();reserve();resize();swap();
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 11/ 21
![Page 12: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/12.jpg)
Einführung Standard Library Numerische Integration
Containerimplementationen
verschiedene Container: vector; list; mapLaufzeitverhalten:
[] einfügen/löschen front back iteratorvector const O(n)+ const+ randomlist const const const Biqueue const constmap O(log(n) O(log(n))+ Bistring const O(n)+ O(n)+ const+ random
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 12/ 21
![Page 13: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/13.jpg)
Einführung Standard Library Numerische Integration
Algorithmen
in <algorithm>:
for_each;find;count;copy;swap;replace;fill;remove;sort;binary_search;partition;min;max;min_element;
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 13/ 21
![Page 14: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/14.jpg)
Einführung Standard Library Numerische Integration
Einfache Beispiele
using std;list<string> s;s.push_back("Birne");s.push_back("Apfel");s.push_back("Kirsche");list<string>::iterator i = find(s.begin(),s.end(),"Apfel");if(i != s.end()) { }s.sort(s.begin(),s.end());list<string>::iterator i = min_element(s.begin(),s.end());int i = 5, j = 9;int m = max(i,j);
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 14/ 21
![Page 15: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/15.jpg)
Einführung Standard Library Numerische Integration
Komplexeres Beispiel
Sortiere Liste nach eigenem Kriterium, Länge des Strings:(stl.cxx)
bool compareLength(const std::string& s1, const std::string& s2) {return s1.length() < s2.length();
}...sort(v.begin(),v.end(),compareLength);min_element(v.begin(),v.end(),compareLength);
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 15/ 21
![Page 16: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/16.jpg)
Einführung Standard Library Numerische Integration
Komplexeres Beispiel
#include <vector>#include <map>#include <iostream>#include <algorithm>#include <cctype>
bool compareLength(const std::string& s1, const std::string& s2) {return s1.length() < s2.length();
}
int main(){
std::vector<std::string> v;std::string s;getline(std::cin,s);while(s.length()) {
v.push_back(s);getline(std::cin,s);
};sort(v.begin(),v.end());//sort(v.begin(),v.end(),compareLength);for(std::vector<std::string>::const_iterator i = v.begin(); i != v.end() ; ++i) {
std::cout << *i << ’\n’;}
}
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 16/ 21
![Page 17: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/17.jpg)
Einführung Standard Library Numerische Integration
Komplexeres Beispiel
#include <vector>#include <map>#include <iostream>#include <algorithm>#include <cctype>
int main(){
std::vector<std::string> v;std::string s;getline(std::cin,s);while(s.length()) {
v.push_back(s);getline(std::cin,s);
};
//count charactersstd::map<char,int> m;for(std::vector<std::string>::const_iterator i = v.begin(); i != v.end() ; ++i) {
std::string s(*i);for(int j = 0 ; j < i->length() ; ++j) {
char c = tolower(s[j]);m[c]++;
}}for(std::map<char,int>::const_iterator i = m.begin(); i != m.end() ; ++i) {
std::cout << i->first << ": " << i->second << ’\n’;}
}
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 17/ 21
![Page 18: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/18.jpg)
Einführung Standard Library Numerische Integration
Übersicht
Einführung
Standard Library
Numerische IntegrationRichardson-ExtrapolationRomberg-Integration
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 18/ 21
![Page 19: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/19.jpg)
Einführung Standard Library Numerische Integration
Richardson-Extrapolation
Richardson-ExtrapolationFür zwei Näherungen Uu und Ug aus einem Verfahren p-terOrdnung mit verschiedenen Diskretisierungen mit denSchrittweiten hu und hg ist
UR =Uu − Ug
(huhg
)p
1 −(
huhg
)p = Ug +Ug − Uu(huhg
)p− 1
(1)
eine bessere Näherung.
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 19/ 21
![Page 20: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/20.jpg)
Einführung Standard Library Numerische Integration
Romberg-Integration
Romberg-Integration
Führe eine Richardson-Extrapolation über die Schrittweitehn = b−a
2n einer summierten Quadraturformel, z.B. Trapezregel,durch.
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 20/ 21
![Page 21: Algorithmen zur Datenanalyse in C++ fileEinführung Standard Library Numerische Integration Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21.05.2012 Algorithmen zur Datenanalyse](https://reader030.vdocuments.mx/reader030/viewer/2022040422/5e15048130eb4247625b8b2b/html5/thumbnails/21.jpg)
Einführung Standard Library Numerische Integration
Romberg-Integration
Romberg-IntegrationAnleitung:
I1,1 =h1
2(f (a) + f (b))(Trapezregel) (2)
In,1 =hn
2
f (a) + f (b) + 2
h1hn
−1∑i=1
f (a + i hn)
(3)
In,k = In+1,k−1 +In+1,k−1 − In,k−1(
hnhn+1
)2(k−1)− 1
(4)
Fehler: E =I1,n+1−I1,n
I1,n
Algorithmen zur Datenanalyse in C++ Hartmut Stadie 21/ 21