• Martin Thoma
  • Home
  • Categories
  • Tags
  • Archives
  • Support me

Recent Posts

Structs in C++

Structs in C++

I guess this article isn't very interesting, except if you have VERY little experience with C / C++. I only give some complete code examples. If you want some text, you could read C++ Programming/Structures (a wikibook). Point Basic example #include using namespace std; struct Point { double x; double … Read More »
Calculate square roots

Calculate square roots

Suppose you have an equation like this: $x^2 = a, \;\;\;\; a \in \mathbb{R}_{\geq 0}$ Your task is to compute the solution $x \in \mathbb{R}_{\geq 0}$. How do you solve this algorithmically? Input and output Write a program that takes two parameters $a, n \in … Read More »
Fractions in C++

Fractions in C++

Today, I thought I should try to implement a class in C++ that deals with fractions. This is actually quite easy as I'll show you. First some math Names When you have a fraction $\frac{a}{b}$ then $a$ is called numerator and $b$ is called denominator. Operations The rules … Read More »
Solving linear equations with Gaussian elimination

Solving linear equations with Gaussian elimination

Please note that you should use LU-decomposition to solve linear equations. The following code produces valid solutions, but when your vector $b$ changes you have to do all the work again. LU-decomposition is faster in those cases and not slower in case you don't have to solve equations with the … Read More »
Generating many prime numbers

Generating many prime numbers

Today, a fellow student claimed that it would take much time to check the first 1,000,000 numbers for primes. I claimed that it would be a matter of seconds to do so for the first 1,000,000,000 numbers. So, lets prove my claim. Trivial approach #include … Read More »
C++ Operator Overloading

C++ Operator Overloading

Operator overloading is heavily used in mathematics. One of the most famous examples I know is "+". If you add two elements from $\mathbb{N}$, you will use the same character "+" as you use for adding two numbers from $\mathbb{R}$. You even use the plus sign when you add matrices … Read More »
Part I: Performance of Matrix multiplication in Python, Java and C++

Part I: Performance of Matrix multiplication in Python, Java and C++

This is Part I of my matrix multiplication series. Part I was about simple matrix multiplication algorithms and Part II was about the Strassen algorithm. Part III is about parallel matrix multiplication. This post is about simple implementations of matrix multiplications. The goal of this post is to find out … Read More »
Vectors in C++

Vectors in C++

Minimal Example #include #include #include using namespace std; int main() { // create an empty vector vector myVector; // insert one element myVector.push_back(5); // insert another element myVector.push_back(4); // insert more elements myVector.push_back(1337); myVector.push_back(42); myVector.push_back(31415); // insert an element which was there … Read More »
Sets in C++

Sets in C++

#include #include #include using namespace std; int main() { // create an empty set of integers set mySet; // insert one element mySet.insert(5); // insert another element mySet.insert(4); // insert more elements mySet.insert(1337); mySet.insert(42); mySet.insert(31415); // insert an element which was there … Read More »
Stacks in C++

Stacks in C++

Minimum Example #include #include using namespace std; int main(){ stack myStack; myStack.push(5); cout << "Size of stack: " << myStack.size() << endl; myStack.push(4); // get the element on the top cout << "Top: " << myStack.top() << endl; // it does NOT automatically pop! cout << "Top: " << myStack.top() << endl; // pop has … Read More »
  • Martin Thoma - A blog about Code, the Web and Cyberculture
  • E-mail subscription
  • RSS-Feed
  • Privacy/Datenschutzerklärung
  • Impressum
  • Powered by Pelican. Theme: Elegant by Talha Mansoor